Update order header through AIF

The following code sample shows how to update an existing order through AIF from outside Dynamics AX 2012 . Scenario is the we need to update some of the fields at header of Order.

 public static int UpdatePurchaseOrder(string _purchId, CallContext CallContextObj = null)  
         KeyField keyField = new KeyField() { Field = "PurchId", Value = _purchId };  
         EntityKey entityKey = new EntityKey();  
         entityKey.KeyData = new KeyField[1] { keyField };  
         EntityKey[] entityKeys = new EntityKey[1] { entityKey };  
         if (CallContextObj == null)  
           CallContextObj = CallContextSettings.getCallContextObject();  
         using (ANPurchOrderServiceClient client = new ANPurchOrderServiceClient())  
           client.ClientCredentials.Windows.ClientCredential.Domain = CredentialsSettings.Domain;  
           client.ClientCredentials.Windows.ClientCredential.UserName = CredentialsSettings.UserName;  
           client.ClientCredentials.Windows.ClientCredential.Password = CredentialsSettings.Password;  
           AxdANPurchOrder PurchaseOrderDoc = client.read(null, entityKeys);  
           AxdEntity_PurchTable purchTable = PurchaseOrderDoc.PurchTable.First();  
           purchTable.ANPublishedState = AxdEnum_ANPublishedState.Published;  
           purchTable.ANPublishedStateSpecified = true;  
           purchTable.action = AxdEnum_AxdEntityAction.update;  
           purchTable.actionSpecified = true;  
           purchTable.PurchLine = null;  
           // Invoke the update operation  
           AxdANPurchOrder newOrder = new AxdANPurchOrder()  
             PurchTable = new[] { purchTable }  
           client.update(CallContextObj, entityKeys, newOrder);  
           return 1;  
       catch (Exception ex)  
       return 0;  

With above code we did as per need, read the purchase order document through read operation, set some fields and last set actions also. when I try to test the application I got some funny strange error

“Invalid entity action.”

This error confuse me also, as I have set the action also. After some research I came to know that read operation of service is returning both header and lines also, which I don’t need that for my scenario. So the fix is that I need to set the line object to null also and then send for update operation.

purchTable.PurchLine = null;

Question after this fix came In my mind is that can we only read header or specific line through read operation ? I will research about this more. If anyone knows this please share your thoughts with me. THANKS

Small job that helps you update the Customer address book association

1:  static void UpdateAddressBookOfCustomer(Args _args) {  
2:      CustTable custTable; //= CustTable::find("2104");  
3:      container addressBooks = ["ALL", "CEU", "CEC"];  
4:      while select firstonly Party from custTable {  
5:          DirAddressBookParty::createPartyRelationsByName(custTable.Party, addressBooks);  
6:      }  
7:  }  

Happy Daxing ūüôā

Number sequence 0 does not exists while Time sheet posting in Dynamics ax R3


After recent upgrade from Dynamics ax 2012 RTM version to R3 I found problem in posting the timesheet and the error was “Number sequence 0 does not exists” This error is not so obvious. After bit of debugging I came to know that Time sheet voucher number sequence is missing. Strange thing is that I am not seeing this Number sequence in Project parameters also. I did check projectTimeSheet configuration key also which needs to be enabled for timesheet. In my cake config key was enabled.

After bit of research I cam to know that Time sheet voucher sequence is new from R2. Previously hour jour was used to post the time sheet.


To make this number sequence appear in the project parameters I have to reload it. I created a simple job below to do this work. After running this job the new hidden number sequence start appearing.

Later Number sequence wizard was run to populate the value of sequence.

static void jobName(Args _args)


   NumberSeqModuleProject NumberSeqModuleProject = new NumberSeqModuleProject();




SSRS Report running Total using Expression?

Suppose we have One Parameter –> Balance = 100 and we needs to show running total on each rows as per example below. One of the way is that to write business logic in RDP class and calculate it. Other way is I have found a great method in SSRS EXPRESSIONS to do this work.

firstamt   SecondAmt   ThirdAmt    RunningTotal
  10                         15                  20          145
  02                        05                  01          153
-30                        -20                -03         100


=RunningValue(Fields!FirstAmt.Value + Fields!SecondAmt.Value + Fields!ThirdAmt.Value
        , Sum
        , Nothing)
    + Parameters!Balance.Value

You may have to change Nothing to a different Scope depending on how your table is set up, it can be your table group Id or Main table Id of SSRS Report.

%d bloggers like this: