Sunday, May 28, 2017

Update customer based on Selection fields in AX

static void updateCustomerStd(Args _args)
{
    CustTable   custTable,getcustTable;
   
    //Function to set customer record
    CustTable createCustTable(CustTable   _custTable)
    {
        AxCustTable     axCustTable;
        SysDictTable    sysDictTable = new SysDictTable(tableNum(CustTable));
        int             i;
        int             fieldCnt;
        FieldId         fieldId;
        ;
        ttsbegin;
        axCustTable = AxCustTable::constructValidateInput(_custTable);
        fieldCnt = sysDictTable.fieldCntWithoutSys();
        for (i=1;i <= fieldCnt;i++)
        {
            fieldId = sysDictTable.fieldCnt2Id(i);
            if (fieldNum(CustTable, AccountNum) != fieldId)
                axCustTable.setFieldAsTouched(fieldId);
        }
        axCustTable.save();
        ttscommit;
        return axCustTable.custTable();
    }
    ;
    ttsBegin;
    select forupdate custTable;
    info(custTable.AccountNum + " " + custTable.CustGroup + " " + custTable.InvoiceAccount);
    custTable.CustGroup = "Corporate";
    custTable.InvoiceAccount = "CH0000239";
    getcustTable = createCustTable(custTable);
    info(getcustTable.AccountNum + " " + getcustTable.CustGroup + " " + getcustTable.InvoiceAccount);
    ttsCommit;
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...