--- title: "Run a message from custom code" slug: "run-a-message-from-custom-code" description: "Run messages from code to import/export data in D365 F&SCM. Learn to create custom classes and adjust arguments for efficient data processing." tags: ["Concept topic"] updated: 2026-03-20T09:42:00Z published: 2026-03-20T17:44:08Z canonical: "docs.staedean.com/run-a-message-from-custom-code" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.staedean.com/llms.txt > Use this file to discover all available pages before exploring further. # Run a message from custom code You can run a message from code. You can do so to export or import data. For example, you can run a message to: - **Import data**: If you want to select a file from a local folder, copy it to your work folder, and process the message to import the data from the file. - **Export data**: If you want to export sales orders that get a specific status. For example, all sales orders that get the status **Delivered**, are exported. ### **Create custom code** To run a message from code, some code customizations are required. As no changes to standard code are allowed, you can: - Extend the desired standard D365 F&SCM class or table, if supported. - Create a new class. The custom class must be run at a point where you want to run the message. Use this custom class to call and run the message. For example, you can extend the post packing slip code, to run a message when the sales order gets the status **Delivered**. In the custom class, add code to: 1. Find the message. For example: `BisConMessageTable myMessage = BisConMessageTable::FindRecid(MyMessageReicd);` 2. Create the message arguments. For example: `BisArgs myArgs = new BisArgs();` 3. Adjust arguments. For example, to add the current record: `myArgs.record(currentRecord); (this is, in the example, the Delivered sales order record)` 4. Optionally, add dialog arguments to define the range. For example: `BisDialogBase myDialog = new BisDialogBase();myDialog.setFieldValue("company", curext());myArgs.dialogBase(myDialog);` > [!NOTE] > **Note** > > Make sure, to add the dialog argument as parameter to the applicable document record range. 5. Run the message. This code processes the message with the defined arguments. For example: `myMessage.run(myArgs);` ## Related - [Run a message asynchronously](/run-a-message-asynchronously.md) - [Apply a custom argument as range parameter to an export](/apply-a-custom-argument-as-range-parameter-to-an-export.md) - [Develop custom code](/develop-custom-code.md) - [Run message from action menu item](/run-message-from-action-menu-item.md) - [Run web service action from action menu item](/run-web-service-action-from-action-menu-item.md) - [Run message](/run-message.md) - [Troubleshoot trigger issues](/troubleshoot-trigger-issues.md)