This post is machine-translated. The original post in german language can be found here.

Calling a SysOperation-based function through code

If you need to run a function - implemented by using the SysOperation-Framework - by code, the following job can show you how you can do this.

static void runSysOperationThroughCode(Args _args)
{
    TutorialSysOperationServiceController controller;
    TutorialSysOperationDataContract dataContract;
    SysOperationStartResult sysOperationStartResult;
    
    controller = TutorialSysOperationServiceController::newFromArgs(new Args()); 

    dataContract = controller.getDataContractObject('_dataContract'); 

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); 

    dataContract.parmFilenameSave(@"c:	empmyFile.txt");
    dataContract.parmCustAccount('US-006');
       
    sysOperationStartResult =
    controller.startOperation();
}

In the above shown example, the data from SysLastValue is used. So the last value are read out and written back to the last value of the current logged on user after the job has finsihed. So the next time the user calls the function "normally" by using a menu item which points to a controller-class, the data entered in the above job will be suggested.

To avoid this, you have to tell the controller-class not to use the last value. This can be archived by one line.

static void runSysOperationThroughCode(Args _args)
{
    TutorialSysOperationServiceController controller;
    TutorialSysOperationDataContract dataContract;
    SysOperationStartResult sysOperationStartResult;
    
    controller = TutorialSysOperationServiceController::newFromArgs(new Args());
    // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
    controller.parmLoadFromSysLastValue(false); 

    dataContract = controller.getDataContractObject('_dataContract');
    dataContract.parmCustAccount('US-006'); 

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    dataContract.parmFilenameSave(@"c:	empmyFile.txt");
        
    sysOperationStartResult =
    controller.startOperation();
}

If you want to call a function without opening a dialog, you can used the follwing example. It's importand to disabled the use of the last value now, because otherwise there will be no dialog when the user opens the function "normally" by using a menu item. 

static void runSysOperationThroughCodeWithoutDialog(Args _args)
{
    TutorialSysOperationServiceController controller;
    TutorialSysOperationDataContract dataContract;
    SysOperationStartResult sysOperationStartResult;
    
    controller = TutorialSysOperationServiceController::newFromArgs(new Args());
    // Don't use SysLastValue (so no values will be retrieved and no one will be stored)
    controller.parmLoadFromSysLastValue(false);

    dataContract = controller.getDataContractObject('_dataContract');
    
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); 

    dataContract.parmFilenameSave(@"c:	empmyFile.txt");
        
    // Don't show dialog here
    controller.parmShowDialog(false);
    
    sysOperationStartResult =
    controller.startOperation();
}
These post applies to following version:
Dynamics AX 2012

Add comment
 
 

 

 
 
 
Posts of the actual month
April 2024
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
2930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.