Data contract in SysOperation framework in D365 F&O

X++ Programming Language >   D365 Forms >   SysOperation framework  

Long Question

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:

 

  1. 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; 
     
               /// <summary> 
               /// Gets or sets the value of the datacontract parameter
                    DateTransactionDate.
               /// </summary> 
               /// <param name="_transDate"> 
               /// The new value of the datacontract parameter 
                    DateTransactionDate; 
               /// </param> 
               /// <returns> 
               ///  The current value of datacontract parameter 
                     DateTransactionDate 
               /// </returns> 
               [DataMemberAttribute('DateTransactionDate') 
                ,SysOperationLabelAttribute(literalStr("@SYS11284")), 
                 SysOperationGroupMemberAttribute('Date'), 
                 SysOperationDisplayOrderAttribute('1')] // today's date 
               public TransDate parmTransDate
                (TransDate _transDate = transDate) 
                {    
                   transDate = _transDate; 
     
                   return transDate; 
                } 
     
               /// <summary> 
               /// Gets or sets the value of the datacontract parameter 
                    DateControl. 
               /// </summary> 
               /// <param name="_allowModifyDate"> 
               /// The new value of the datacontract parameter 
                    DateControl; 
               /// </param> 
               /// <returns> 
               ///  The current value of datacontract parameter 
                      DateControl 
               /// </returns> 
               [DataMemberAttribute('DateControl'), 
               SysOperationLabelAttribute("Enable date control"), 
               SysOperationGroupMemberAttribute('Date'), 
               SysOperationDisplayOrderAttribute('0')] 
               public NoYesId parmAllowModifyDate
                (NoYesId _allowModifyDate   = allowModifyDate) 
                { 
                  allowModifyDate = _allowModifyDate; 
                  return allowModifyDate; 
                } 
     
               /// <summary> 
               /// Validates the dialog values for errors. 
               /// </summary> 
               /// <returns> 
               /// false if an error has occurred in the dialog values;
                   otherwise, true . 
               /// </returns> 
               /// <remarks> 
               /// The dialog values are handled through the contract. 
               /// </remarks> 
               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.

  2. 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.