Mumble
Mumble

Reputation: 141

Mark checkbox in all companies AX2012

I added a checkbox in PurchParameters table which name is setExchRateVal and I want to mark true this field in my all companies without sql operations.

How can i do this in AX with job?

I tried this but it's not done,

PurchParameters purchParameters ;

while select forUpdate crossCompany purchParameters
{
    purchParameters.setExchRateVal = NoYes::Yes;
    purchParameters.update();
    //info(strFmt("%1 - %2", purchParameters.SetExchRateVal, purchParameters.dataAreaId));
}

AX ERROR : Update operations are not allowed across companies.

Upvotes: 1

Views: 187

Answers (1)

Alex Kwitny
Alex Kwitny

Reputation: 11564

The error is clear. You can't do crossCompany and updates in the same select query. Method 2 below is closer to what you're doing. When updating parameter tables, it can be done a few ways because of the Key on the table.

See below:

PurchParameters purchParametersUpdate;
PurchParameters purchParametersSeek;
DataArea        dataArea;

// Method 1
ttsBegin;
while select dataArea
{
    changeCompany(dataArea.id)
    {
        purchParametersUpdate = PurchParameters::find(true);
        purchParametersUpdate.setExchRateVal = NoYes::Yes;
        purchParametersUpdate.update();
    }
}
ttsCommit;


// Method 2
ttsBegin;
while select crossCompany purchParametersSeek
{
    purchParametersUpdate = null;

    select firstOnly forUpdate purchParametersUpdate
        where purchParametersUpdate.RecId == purchParametersSeek.RecId;

    if (purchParametersUpdate)
    {
        //purchParametersUpdate.setExchRateVal = NoYes::Yes;
        purchParametersUpdate.update();
    }
}
ttsCommit;

info("Done");

Upvotes: 3

Related Questions