Search code examples
c#web-servicesdynamics-ax-2009x++ax

Can't update decimals with an AIF Webservice in AX 2009


I've created an AIF web-service in AX 2009 with the standard wizard from a query. Now it looks like that every thing works, except in the update. I'm not able to write back fields from the type "decimal". But "string" fields works without problems.

If you look into the code below, the field "PickQty" is an decimal, that doesn't work and the "PickQtyMob" is a string field, that works.

If I only update PickQty I get into the update from the service in AX but not in the parm method.

And I don't get any error messages or exceptions.

Code snippet for the update: try { MOBBatchPickServiceUpdateRequest updateRequest = new MOBBatchPickServiceUpdateRequest(); updateRequest.MOBBatchPick = new AxdMOBBatchPick(); updateRequest.MOBBatchPick.BatchPick = new MOBBatchPickService.AxdEntity_BatchPick[1]; updateRequest.MOBBatchPick.BatchPick[0] = new MOBBatchPickService.AxdEntity_BatchPick();

    updateRequest.EntityKeyList = new MOBBatchPickService.EntityKey[mobBatchPick.BatchPick.Length];

    for (i = 0; i < mobBatchPick.BatchPick.Length; i++)
    {
        updateRequest.EntityKeyList[i] = new MOBBatchPickService.EntityKey();
        updateRequest.EntityKeyList[i].KeyData = new MOBBatchPickService.KeyField[1];

        updateRequest.EntityKeyList[i].KeyData[0] = new MOBBatchPickService.KeyField();
        updateRequest.EntityKeyList[i].KeyData[0].Field = "PickRequestNum";
        updateRequest.EntityKeyList[i].KeyData[0].Value = mobBatchPick.BatchPick[i].PickRequestNum;

        mobBatchPick.BatchPick[i].PickQty = mobBatchPick.BatchPick[i].PickQty; // decimal: Doesn't work
        mobBatchPick.BatchPick[i].PickQtyMob = mobBatchPick.BatchPick[i].PickQty.ToString(); // string: Works

        mobBatchPick.BatchPick[i].action = MOBBatchPickService.AxdEnum_AxdEntityAction.update;

    }// for


    updateRequest.MOBBatchPick = mobBatchPick;
    batchPickClient.update(updateRequest);

}
catch (Exception _exception)
{
    MessageBox.Show(_exception.ToString());
}

Solution

  • I solved the problem by adding the field into the initMandatoryFieldsMap method in AX like this:

    protected void initMandatoryFieldsMap()
    {
        super();
        this.setParmMethodAsMandatory(classNum(AxMobBatchPick),methodStr(AxMobBatchPick,parmPickty));
    }