Sys Operation framework – Adding Class to Batch Task/making Journalized

Problem statement:

We have batchable  class that needs to be added to Batch Task form (System Administration> Batch>View Task) so we can plan batch job executions like if any dependencies or sequencing needs to be managed between the batch classes.

For such tasks class should be Journalized.

We know that if we are using old RunBaseBatch framework we can make the class Journalized by overriding the method canGoBatchJournal() and let it return true.

But if we have implemented the Batch using new SysOperation framework then we need to following things.

We need to have Controller class, as Batch task will be scheduled based on it.
Controller class needs to be decorated using attribute “[SysOperationJournaledParametersAttribute(true)]”
Main and new method should have important information provided as heighted below. These needed for initializing the parameters in Batch Task.

6-3-2016 9-55-47 PM

6-3-2016 9-56-33 PM

6-3-2016 9-57-03 PM

Thanks you

Happy Daxing 🙂


Settlements (Technical Utility methods)

Piece of code that checks if the invoice is already marked with some payment or not

 protected boolean checkIfAlreadyMark(CustVendTransOpen _custVendTransOpen)  
   specTransManager specTransManager = specTransManager::construct(_custVendTransOpen);  
   return specTransManager.existForOtherSpec(, _custVendTransOpen.TableId, _custVendTransOpen.RecId);  

Piece of code that settles the invoice with the payment

 protected void markSettlement(CustVendTransOpen _custVendTransOpen)  
   CustVendOpenTransManager manager = CustVendOpenTransManager::construct(ledgerJournalTrans);  
   manager.updateTransMarked(_custVendTransOpen, true);  

Get default financial dimension values through X++ code

This topic is not new and we have lots of blogs available on it. Yasir Co-blogger also explained this quite well in his blog. The purpose to share this again here that I have did some minor modifications in his job to get both attributes (Value and Name) for Default dimension. Complete code is here.

static void GetDefaultDimensionAttributeName(Args _args)
    DimensionAttributeValueSetStorage    dimStorage;
    HcmPositionDefaultDimension          HcmPositionDefaultDimension;
    DimensionAttribute  DimensionAttribute;
    Counter                                               i;
    DimensionAttribute          dimAttr;
    DimensionAttributeValue     dimAttrValue;
    Common                      common;
    DictTable                   dictTable;
    str                         Name;
    str                         value;

    // get the dimension value from position    
    HcmPositionDefaultDimension = HcmPositionDefaultDimension::findByPositionLegalEntity(HcmPosition::findByPosition("000001").RecId,CompanyInfo::find().RecId);

    // make the dimension storage object    
    dimStorage = DimensionAttributeValueSetStorage::find(HcmPositionDefaultDimension.DefaultDimension);

    for (i=1 ; i<= dimStorage.elements() ; i++)
        // get attribute select here.
        select firstonly dimAttrValue
        where dimAttrValue.RecId == dimStorage.getValueByIndex(i)
        join dimAttr
            where dimAttr.RecId == dimAttrValue.DimensionAttribute;

        if (dimAttr && dimAttrValue)
            dictTable = new DictTable(dimAttr.BackingEntityType);
            common = dictTable.makeRecord();

            if (common.TableId)
                select common where common.(dimAttr.KeyAttribute) == dimAttrValue.EntityInstance;
                name = common.(dimAttr.NameAttribute);
                value = common.(dimAttr.ValueAttribute);
        info(dimAttr.Name +"----" +value + "----"+name);

output image

we can check the other examples on same topic from Yasir’s Blog – Microsoft Dynamics AX

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 =, 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

%d bloggers like this: