Data contract in SysOperation framework in D365 F&O
X++ Programming Language > D365 Forms > SysOperation framework
486
Answer:
Data contract in SysOperation framework in D365 F&O
Data contract: The data contract (CustBalanceDataContract) is the model class in which we define which attributes we need for our operation, commonly set as parameters by the user in a dialog. It's just a model class with an attribute, in which we will use the DataContractAttribute attribute to decorate our class declaration. For each member variable, we have to define one parm methods using the attribute DataMemberAttribute, which will work like getter setter method. Additionally, if we want some more methods to be available to us, we can also extend the standard class SysOperationDataContractBase. With this class, we can define how our basic dialog will look to the user. We can define our labels, groups, sizes, and types of parameters.
Carry out the following steps in order to complete this recipe:
- In the VS project , create a new class called CustBalanceDataContract with the following code snippet:
[ DataContractAttribute, SysOperationContractProcessingAttribute (classStr(CustBalanceUIBuilder)), SysOperationGroupAttribute ('Date',"@ApplicationPlatform:SingleSpace", '1') ] class CustBalanceDataContract implementsSysOperationValidatable { NoYesId allowModifyDate; TransDate transDate; str packedQuery; /// /// Gets or sets the value of the datacontract parameter DateTransactionDate. /// /// /// The new value of the datacontract parameter DateTransactionDate; /// ////// The current value of datacontract parameter DateTransactionDate /// [DataMemberAttribute('DateTransactionDate') ,SysOperationLabelAttribute(literalStr("@SYS11284")), SysOperationGroupMemberAttribute('Date'), SysOperationDisplayOrderAttribute('1')] // today's date public TransDate parmTransDate (TransDate _transDate = transDate) { transDate = _transDate; return transDate; } ////// Gets or sets the value of the datacontract parameter DateControl. /// /// /// The new value of the datacontract parameter DateControl; /// ////// The current value of datacontract parameter DateControl /// [DataMemberAttribute('DateControl'), SysOperationLabelAttribute("Enable date control"), SysOperationGroupMemberAttribute('Date'), SysOperationDisplayOrderAttribute('0')] public NoYesId parmAllowModifyDate (NoYesId _allowModifyDate = allowModifyDate) { allowModifyDate = _allowModifyDate; return allowModifyDate; } ////// Validates the dialog values for errors. /// ////// false if an error has occurred in the dialog values; otherwise, true . /// ////// The dialog values are handled through the contract. /// public boolean validate() { boolean ret = true; if(!transDate && allowModifyDate) ret = checkFailed('Transaction date cannot be empty'); return ret; } [DataMemberAttribute, AifQueryTypeAttribute ('_packedQuery', querystr(CustTableSRS)) ] public str parmQuery(str _packedQuery = packedQuery) { packedQuery = _packedQuery; return packedQuery; } public Query getQuery() { return new Query(SysOperationHelper::base64Decode(packedQuery)); } public void setQuery(Query _query) { packedQuery =SysOperationHelper::base64Encode(_query.pack()); } }Here, SysOperationGroupAttribute specifies how we group the contract parameters and provides the order in which to display the group. Data contract also implements the SysOperationValidatable interface, due to which we need to override the Validate() method and validate parameters before actual execution begins. Using SysOperationContractProcessingAttribute, we specify the UIbuilder class to modify the parameter's behavior at runtime. We will create this UI builder class later in this chapter.
-
In the VS project , create a new class called CustBalanceController with the following code snippet:
This Particular section is dedicated to Question & Answer only. If you want learn more about X++ Programming Language. Then you can visit below links to get more depth on this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.