Welcome at schweda.net | EN | DE
 
 
 
 
 
This post is machine-translated. The original post in german language can be found here.

In the following scenario, all records of a temporary table are to be passed to a SysOperation construct.

For that we need:

  • In the DataContract, a parm-method that takes a container
  • In the controller, a logic that iterates the records of a calling data source and packs it into a container, and passes it to the service using the above method
  • In the service class we need code, which unpacks and processed the transferred container

 

Controller

class TutorialSysOperationController extends SysOperationServiceController
{
}

In the new()-method, we link the controller to the service class.

void new()
{
    super();

    this.parmClassName(classStr(TutorialSysOperationService));
    this.parmMethodName(methodStr(TutorialSysOperationService, runService));
}

The main()-method is the classic entry point when the controller is called via a MenuItem. Here, the calling data source is passed to the service class using the DataContract.

public static void main(Args _args)
{
    TutorialSysOperationController controller;
    SysOperationStartResult sysOperationStartResult;
    TutorialSysOperationDataContract dataContract;
    Set recordSet;
    TmpInventTable tmpInventTable;

    controller = new TutorialSysOperationController();
    controller.parmArgs(_args);

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    // Get calling datasource
    if(_args.record() && _args.dataset() == tableNum(TmpInventTable))
    {
        tmpInventTable = _args.record();

        recordSet = new Set(Types::Record);
        while select tmpInventTable
        {
            recordSet.add(tmpInventTable);
        }
    }

    // Put records from calling datasource into dataContract
    dataContract = controller.getDataContractObject();
    if(dataContract is TutorialSysOperationDataContract)
    {
        dataContract.parmRecordCon(recordSet.pack());
    }

    sysOperationStartResult =
    controller.startOperation();

}

 

DataContract

[DataContractAttribute]
public class TutorialSysOperationDataContract
{
    container recordCon;
}

 

[DataMemberAttribute, SysOperationControlVisibilityAttribute(false)]
public container parmRecordCon(container _recordCon = recordCon)
{
    recordCon = _recordCon;

    return recordCon;
}

 

Service

class TutorialSysOperationService extends SysOperationServiceBase
{
}

The method runService() is the actual service method. By means of the attribute SysEntryPointAttribute we control here that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService(TutorialSysOperationDataContract _dataContract)
{   
    Set recordSet;
    SetEnumerator se;
    Common record;
    TmpInventTable tmpInventTable;

    // Process records
    if(conLen(_dataContract.parmRecordCon()) > 0)
    {
        recordSet = Set::create(_dataContract.parmRecordCon());
        se = recordSet.getEnumerator();
        while(se.moveNext())
        {
            record = se.current();

            switch(record.TableId)
            {
                case tableNum(TmpInventTable):   
                    tmpInventTable = record;
                    info(strFmt("%1 %2", tmpInventTable.ItemId, tmpInventTable.ItemName));
                    break;
                default:                   
                    info(strFmt("%1", record.RecId));
            }
        }
    }
}
These post applies to following versions:
Dynamics AX 2012

Add comment

 

 
Feeds
RSS RSS feed
RSS RSS feed (Comments)
RSS RSS feed (Category)
 
 
posts of the actual month
Juni 2017
MoDiMiDoFrSaSo
 1234
567891011
12131415161718
19202122232425
2627282930 
 
 
© 2006-2016 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.