This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
Dynamics AX 2012
Very useful post, thanks a lot |
|
|
|
|
|
|
|
This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In the following scenario, all records of a temporary table are to be passed to a SysOperation construct.
For that we need:
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)); } } } }