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 accessor method (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;
    MultiSelectionHelper multiselectionHelper;

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

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    // Get marked records from calling form
    if (_args && _args.caller() is FormRun)
    {
        recordSet = new Set(Types::Record);
        multiselectionHelper = MultiSelectionHelper::createFromCaller(_args.caller());   
        
        tmpInventTable = multiselectionHelper.getFirst();
        while (tmpInventTable)
        {
            recordSet.add(tmpInventTable);
            
            tmpInventTable = multiselectionHelper.getNext();
        }
    }

    // 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
Dezember 2018
MoDiMiDoFrSaSo
 12
3456789
10111213141516
17181920212223
24252627282930
31 
 
 
© 2006-2018 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.