Tuesday, March 10, 2020

Sysda classes in D365

Sysda Classes with example 

class RunnableClass1
{     
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
 
//SysDa insetopertaion includes using two API's
//SysDainsertobject - used to create insert_recordset statement
//SysDainsertstatement - used to perform insert_recordset operation

//sample query
    //insert_recordset  CustomRDPTmpTable(AccountNum, BankAccount, ContactPersonId, CustGroup, Currency)
    //select AccountNum, BankAccount, ContactPersonId, CustGroup, Currency from CustTable
    //where CustTable.AccountNum == 'BRMF-000001'
public static void main(Args _args)
    {

//first part- using sysdainsertobject
//Target table
CustomRDPTmpTable customtable;
   
//initialize sysdainsertobject 
var insertobject = new SysDaInsertObject(customtable);

//add fields to be inserted in target table
insertobject.fields()
.add(fieldStr(CustomRDPTmpTable, AccountNum))
.add(fieldStr(CustomRDPTmpTable, BankAccount))
.add(fieldStr(CustomRDPTmpTable, ContactPersonId))
.add(fieldStr(CustomRDPTmpTable, Currency))
.add(fieldStr(CustomRDPTmpTable, CustGroup));

//insert_recordset  CustomRDPTmpTable(AccountNum, BankAccount, ContactPersonId, CustGroup, Currency)

//Second part- creating select statement using SysDaqueryobject
//source table
CustTable custtable;

//intialize sysdaqueryobject
var qe = new SysDaQueryObject(custtable);

//select fields from source table
//select AccountNum, BankAccount, ContactPersonId, CustGroup, Currency from CustTable
var s1 = qe.projection()
.add(fieldStr(CustTable, AccountNum))
.add(fieldStr(CustTable, BankAccount))
.add(fieldStr(CustTable, ContactPersonId))
.add(fieldStr(CustTable, Currency))
.add(fieldStr(CustTable, CustGroup));

//adding where clause  
qe.whereClause(new SysDaEqualsExpression(
new SysDaFieldExpression(custtable, fieldStr(CustTable, AccountNum)),
new SysDaValueExpression('BRMF-000001')));

//now select query is complete
//select AccountNum, BankAccount, ContactPersonId, CustGroup, Currency from CustTable
//where CustTable.AccountNum == 'BRMF-000001'

//third part - Assign the query to insert statement
insertobject.Query(qe);

//fourth part - using SysDainsetstatement
//execute the query using executequery method
var insertstatement = new SysDaInsertStatement();

ttsbegin;
insertstatement.executeQuery(insertobject);
ttscommit;

//printing target values
CustomRDPTmpTable customloc;

select * from customloc where AccountNum == 'BRMF-000001';
Info(any2Str(customloc.AccountNum) + " " + any2Str(customloc.Currency) + " " + any2Str(customloc.CustGroup));

    }

}



containerLineQueryObject.whereClause(new SysDaEqualsExpression(

                    new SysDaFieldExpression(containerLineInventDim, fieldStr(InventDim, InventDimId)),

                    new SysDaFieldExpression(_containerLine, fieldStr(WHSContainerLine, InventDimId)))

            .and(new SysDaEqualsExpression(

                    new SysDaFieldExpression(containerLineInventDim, fieldStr(InventDim, InventStatusId)),

                    new SysDaFieldExpression(_loopInventDim, fieldStr(InventDim, InventStatusId)))));
------------------------------------------------------------------------------------------------------

For the Update_recordset, you’ll create QueryObjects the same as Insert_recordset(), and pass that to a update object and setup the ‘settingClause’.  This will also need to be extended.



        AllFieldTypesTable source;

        var qe = new SysDaQueryObject(Source);



        var uo = new SysDaUpdateObject(source);

        uo.settingClause()

           .add(fieldStr(AllFieldTypesTable, Id), new SysDaPlusExpression(new SysDaFieldExpression(source, fieldStr(AllFieldTypesTable, Id)), new SysDaValueExpression(100)))

           .add(fieldStr(AllFieldTypesTable, String), new SysDaValueExpression("Banana"));





        new SysDaUpdateStatement().execute(uo);

Form Methods by COC Extension in D365

Form Datasource Method in Extension

[ExtensionOf(formDataSourceStr(LogisticsElectronicAddress,LogisticsElectronicAddress))]
final class CustomLogisticsElectronicAddressform_Extenison
{
public void modified()
    {
          FormDataObject fdo = any2Object(this) as FormDataObject;
          FormDataSource fds = fdo.datasource();
          LogisticsElectronicAddress logisticsElectronicAddress = fds.formRun().dataSource(formDataSourceStr(smmOutlookMyContacts,LogisticsElectronicAddress)).cursor();

/// In other way we can get form datasource value by as below
/// FormDataSource  logisticsElectronicAddress_DS = element.logisticsElectronicAddress_DS  as FormDataSource  

          next modified();

          logisticsElectronicAddress.enableFields();
    }
}

Form Datasource Field Method in Extension

[ExtensionOf(formDataFieldStr(InventJournalCount,JAD_InventJournalTrans,FailureReasonId))]
final class JADInventJournalCountJAD_InventJournalTransDSField_Extension
{
    public void modified()
    {
        FormDataObject fdo = any2Object(this) as FormDataObject;
        FormDataSource fds = fdo.datasource();
        JAD_InventJournalTrans jAD_InventJournalTrans = fds.formRun().dataSource(formDataSourceStr(InventJournalCount,JAD_InventJournalTrans)).cursor();
        InventJournalTrans  inventJournalTrans = fds.formRun().dataSource(formDataSourceStr(InventJournalCount,InventJournalTrans)).cursor();

        next Modified();
            
 jAD_InventJournalTrans.Description =  JAD_WarehouseFailureReason::find(jAD_InventJournalTrans.FailureReasonId, JAD_WarehouseFailureReasonType::Counting).Description;
 jAD_InventJournalTrans.InventJournalTrans = inventJournalTrans.RecId;
    }

}