Wednesday, May 20, 2020

Update Recordset for Updating other company records by Crosscompany in Ax 2012

Update Recordset by crossCompany

  while select BB_CompanyId from bB_RippleTable where bB_RippleTable.BB_PriceExpiration ==            NoYes::Yes
    {
      // You must disable update method, database log and alerts, otherwise compiler will throw an    error, for example:
        inventTable.skipDataMethods(true);
        inventTable.skipDatabaseLog(true);
        inventTable.skipEvents(true);
        update_recordSet crossCompany inventTable
        setting RepairFee_BB = 100
        where inventTable.ItemId == "fit123"
        && inventTable.dataAreaId == bB_RippleTable.BB_CompanyId;
     
        info('done');
    }

///note : some time it will not work for all users the user must have admin rights to do, so in that
// case we doing in different way as below

   while select CompanyId from bB_RippleTable where bB_RippleTable.PriceExpiration == NoYes::Yes
    {
        changeCompany(bB_RippleTable.CompanyId)
        {
            ttsBegin;
            inventTableModule = null;
            select forUpdate inventTableModule
                where inventTableModule.ItemId == _itemid
                && inventTableModule.ModuleType == ModuleInventPurchSales::Purch
                && inventTableModule.dataAreaId == bB_RippleTable.CompanyId;

            if(inventTableModule.RecId != 0)
            {
                inventTableModule.PriceExpirationDate_BB = _date;
                inventTableModule.update();
                info(strFmt("@BBX5747",inventTableModule.PriceExpirationDate_BB,bB_RippleTable.CompanyId));
            }
            ttscommit;
        }
    }

Thursday, April 16, 2020

How to disable Standard delete button in D365 Form

Disabled delete button in D365

FormCommandButtonControl delButton;

    public void init()
    {
        #SysSystemDefinedButtons

        super();
delButton = this.control(this.controlId(#SystemDefinedDeleteButton)) as FormCommandButtonControl;
        delButton;.visible(false);
    }

Wednesday, April 1, 2020

COC Methods for Extending form control enable or visible in D365

Form Control Methods in D365


[ExtensionOf(formstr(CustFreeInvoice))]
public final class CustFreeInvoice_Form_Extension
{
    void init()
    {
        FormRun formRun = this;
        FormCheckBoxControl ReleaseOrderOnCreditLimit = formRun.design().controlName(formControlStr(CustFreeInvoice,ReleaseOrderOnCreditLimit));

        FormDataSource CustInvoiceTable_DS = formRun.dataSource(formDataSourceStr(CustFreeInvoice,CustInvoiceTable));
         
        next init();

   /*
Other way to get control name
                                                                formRun.design().controlName('TaxVATNum'),
                                                                formRun.design().controlName('VATNum'),
                                                                formRun.design().controlName('NumCheckCtrl'),
                                                                formRun.design().controlName('ViesCheckCtrl'),

*/

        ReleaseOrderOnCreditLimit.visible(false);

}

}

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;
    }

}