Thursday, August 11, 2016

FA upload ax 2012

//FA upload ax 2012
static void UploadFAseetbook(Args _args)
{
    CommaTextIO           csvFile;
    container                   readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField              dfFileName;
    FileName                    fileName;
    int                         Ccount;
    Struct                      struct;
    DimensionDefault            DimensionDefault;
    AssetId         assetid;
    AssetBookId     bookid;
    Description     NAme;
    str usedfromdate;
    date useddate;
    AssetGroupid  AssetGroup;
    AssetBook   assetBook;
    container   ledgerDimension;
    int i;
    AssetTable      assetTable;
    DimensionDefault DefaultDimensionCreate(Description _BU,Description _CC,Description _Department)
    {
        DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault result;
        int j;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue; //DimensionAttributeValueCombination
        container conAttr = ["BusinessUnit","CostCenter","Department"]; //101,106,1
        container conValue;
        str dimValue;
        conValue = [_BU,_CC,_Department];
        dimValue = "";
        j = 0;
        for (j = 1; j <= conLen(conAttr); j++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,j));
            if (dimensionAttribute.RecId == 0)
            {
                continue;
                //control will not go down
            }
            dimValue = conPeek(conValue,j);
            if (dimValue != "")
            {
                dimensionAttributeValue =
                dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
        result = valueSetStorage.save();

        return result;
    }
    ;
    inserted =0;
    #File
   
   
    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);

    if (dialog.run())
    {
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
       
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            if(readCon)
            {
                icount++;
                assetid = conPeek(readCon,2);
                NAme = conPeek(readCon,9);
                bookid = conPeek(readCon,3);
                AssetGroup = conPeek(readCon,1);
                usedfromdate = conPeek(readCon,12);
               
                assetTable.clear();
                assetTable.AssetId = assetid;
                assetTable.Name = NAme;
                assetTable.NameAlias = NAme;
                assetTable.AssetGroup = AssetGroup;
                assetTable.AssetType = AssetType::Tangible;
                assetTable.Quantity = 1;
                assetTable.Location = conPeek(readCon,16);
                assetTable.insert(); 
                i++;
               
                assetBook.clear();
                assetBook = AssetBook::find(assetid,bookid,true);
                ttsBegin;
                select forUpdate assetBook
                    where assetBook.AssetId == assetid;
                if(assetBook)
                {
                    assetBook.AssetGroup = AssetGroup;
                    assetBook.BookId = bookid;
                    assetBook.Status = AssetStatus::NoAcquisition;
               
                    DimensionDefault = DefaultDimensionCreate(conPeek(readCon,8),conPeek(readCon,15),conPeek(readCon,13));
                    assetBook.DefaultDimension = DimensionDefault;
               
                    assetBook.PostingProfile        = conPeek(readCon,10);
                    assetBook.Depreciation          = NoYes::Yes;
                    assetBook.LifeTime              = conPeek(readCon,14);
                    assetBook.AcquisitionPrice      = conPeek(readCon,5);
                    assetBook.AcquisitionDate       =  str2Date(conPeek(readCon,4),213);
                    assetBook.UsedFromDate          = str2Date(usedfromdate,213);
                    assetBook.ServiceLife           = conPeek(readCon,11);
                    assetBook.LifeTimeRest          = conPeek(readCon,7);
                    assetBook.update();
                }
                else   
                {
                    info(strFmt("Value Model not updated,%1,%2",assetid));
                }
                ttsCommit;
               
            }
        } 
        info(strFmt("No of Record updated %1",i));
    }
}
//
               

Shrinking DB

//Shrinking DB

USE MicrosoftDynamicsAX;
ALTER DATABASE MicrosoftDynamicsAX
SET RECOVERY SIMPLE;
DBCC SHRINKFILE (MicrosoftDynamicsAX_Log, 0);
ALTER DATABASE MicrosoftDynamicsAX
SET RECOVERY FULL;

Calling Caller FORM method in calling FORM ax 2012

//Calling Caller FORM method in calling FORM ax 2012
if (formHasMethod(element.args().caller(), identifierStr('MthodName')))
    {
        element.args().caller().mthodName("");
    }

Deleting and Regenerating all target mapping DMF DIF Error

//Deleting and Regenerating all target mapping DMF DIF Error

static void San_DeletionRegenerateDMFTgtMapping(Args _args)
{
    DMFTargetXMLToEntityMap     dmfTargetXMLToEntityMap;
    DMFEntity                   dmfEntity;
    ;
    ttsBegin;
    delete_from dmfTargetXMLToEntityMap;
    ttsCommit;
    while select dmfEntity
    {
        DMFTargetXMLToEntityMap::generateMapping(dmfEntity);
    }
    info("Done");
}

Customize Database Log Table in AX 2012

//Customize Database Log Table in AX 2012


Class--> FCCLog
//Create Table FCCLogTable to track
//Create Enum FCCEventTypes -- (Ex: Insert,Update,Delete)
// Create Enum FCCLogTransaType -- (ex: Transaction Type (worker,Dirparty,transaction,master)
//Class declaration
class FCCLog
{
    FCClLog       Log;
    FCCEventType        _evType;
    FCCLogTransType     _trType;
    Common              oldrec,newrec;
    HcmWorkerRecId      workerrec;
    TableId             table;
    RefRecId            refRec;
    real        oldv,newv,diff;
}
//Insert Log Table
void insertLog(FieldName fld,str oldVal, str newVal,RefRecId rec)
{
    SysDictTable dictTable = new SysDictTable(table);
    ;
    if(_evType!= FCCEventType::Update || oldVal != newVal)
    {
        Log.clear();
        Log.HcmWorkerRecId = workerrec;
        Log.workerName = HcmWorker::find(workerrec).name();
        Log.Diff = diff;
        Log.FieldNm = fld;
        Log.LogTransType = _trType; //Table name
        Log.EventType = _evType;  // insert,Delete,Update
        Log.OldValue = oldVal;
        Log.NewValue = newVal;
        Log.Reference = rec;
        Log.Table = table;
        log.tablenm = dictTable.label();
        Log.User = curUserId();
        Log.transDate = today();
        Log.FCCTime = DateTimeUtil::time(DateTimeUtil::utcNow());
        Log.insert();
    }
}
//new method
void new(Common rec,FCCEventType evType)
{
    HcmWorker       worker;
    DirPerson   DirPartyTable;
    ;
    _evType = evType;
    switch (rec.TableId)
    {
        case tablenum(HcmWorker):
            _trType = FCCLogTransType::EmployeeDetails;
            worker = rec;
            workerrec = worker.recid;
            table = worker.TableId;
            refrec = rec.RecId;
            this.LogTable(rec);
            break;
        case tablenum(DirPartyTable):
            _trType = FCCLogTransType::EmployeeDetails;
            DirPartyTable = rec;
            worker = HcmWorker::findByPerson(DirPartyTable.RecId);
            workerrec = worker.RecId;
            if(workerrec)
            {
                table = DirPartyTable.TableId;
                refrec = rec.RecId;
                this.LogTable(rec);
            }
            break;
        default:
            break;
    }
}
//Log Table find
void LogTable(Common rec)
{
    SysDictTable dictTable = new SysDictTable(rec.TableId);
    SysDictField dictField;
    FieldId fieldId = dictTable.fieldNext(0);
    str oldVal,newVal;
    ;
    try
    {
        oldrec = rec.orig();
        newrec = rec;
        if(_evType == FCCEventType::Update)
        {
            while (fieldId)
            {
                dictField = dictTable.fieldObject(fieldId);
                if (dictField.isSql() && !dictField.isSystem() && dictField.arraySize() == 1
                    && dictfield.allowEdit() && dictfield.baseType() != Types::Container)
                {
                    oldVal =strfmt("%1",oldrec.(fieldId));
                    newVal = strfmt("%1",rec.(fieldId));
                    if(dictField.baseType() == Types::Int64 || dictField.baseType() == Types::Integer ||
                        dictField.baseType() == Types::Real)
                        {
                            diff = rec.(fieldId) - oldrec.(fieldId);
                        }
                    if(oldVal != newVal)
                    {
                        this.insertLog(dictField.label(),oldVal, newVal,rec.RecId);
                    }
                }
  else
  {
   oldVal =strfmt("%1",oldrec.(fieldId));
                     newVal = strfmt("%1",rec.(fieldId));
   this.insertLog(dictField.label(),oldVal, newVal,rec.RecId);
  }
                fieldId = dictTable.fieldNext(fieldId);
            }
        }
        else if(_evType == FCCEventType::Insert)
        {
            this.insertLog("","","",newrec.RecId);
        }
        else if(_evType == FCCEventType::Delete)
        {
            this.insertLog("","","",0);
        }
    }
    catch
    {
        return;
    }
}

//Adding Method in Table level
//delete,Update,Insert
new FCCLog(this,FCCEventTYpe::Delete);
new FCCLog(this,FCCEventTYpe::Insert);
new FCCLog(this,FCCEventTYpe::Update);

Submit/Approve/Reject/Recall/Cancel workflow from external webservice ax 2012 - Workflow Esacalating

//Refer below code and rewritten as per you workflow type and document table.

Note:
For
Action (Approve, Reject, Request change)
Cancel
Resubmit

Need to execute seperate set of code below in job.

static void WorkflowAutoxplusplus(Args _args)
{
    recId                                   recId;
    SAN_LeaveTrans                           leaveTrans;
    SAN_LeaveRequestSubmitManager            leaveRequestManager;
    WorkflowComment                         note;
    FormRun                                 formRun;
    WorkflowVersionTable                    versionTable;
    //WorkflowTable                           workflowTable;
    tableId                                 tableId;
    WorkflowTypeName                        workflowTypeName    = workflowtypestr(SAN_LeaveTransWFType);
    Args                                    args                = new Args();
    Args                                    argsCheck           = new Args();
    WorkflowCorrelationId                   workflowCorrelationId;
    FormRun                                 callerForm;
    SAN_LeaveTransWFTypeSubmitManager        resubmit;
    SAN_LeaveTransWFTypeCancelManager        cancel;
    SysWorkflowApprovalService      workflowservice;
    WorkflowWorkItemTable   workitemTable;
    recId                    elementTableRecId;
    WorkflowActionTable      actionTable;
    SysWorkflowTable        workflowTablecheck;
    WorkflowWorkItemTable WorkflowWorkItemTablechk,WorkflowWorkItemTableins;
 
    //Function Do message processing - For escalating workflow work items Auto
    void doMessageProcessing()
    {
        #Event
        Microsoft.Dynamics.AX.Framework.Workflow.Runtime.WorkItemActivityContext activityContext;
        SysWorkflowMessageTable     workflowMessageTable;
        WorkflowWorkItemTable       workflowWorkItemTable;
        SysWorkflowElementTable     workflowElementTable;
        SysWorkflowTable            workflowTable;
        WorkflowNotificationStaging workflowNotificationStaging;
        SysWorkflowNotificationManager  notificationManager;
        ;
        notificationManager = SysWorkflowNotificationManager::construct();
        SysWorkflowMessageQueueManager::runNow();
        select count(RecId) from workflowMessageTable where
            workflowMessageTable.MessageLifeCycleState == WorkflowMessageLifeCycleState::Queued;
     
        while select workflowWorkItemTable where
            (workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem ||
             workflowWorkItemTable.Type == WorkflowWorkItemType::Escalated) &&
            (workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending ||
             workflowWorkItemTable.Status == WorkflowWorkItemStatus::Delegated) &&
            workflowWorkItemTable.DueDateTime < DateTimeUtil::getSystemDateTime()
        {
            WorkflowWorkItem::escalateWorkItem(workflowWorkItemTable);
        }
        //take action on elements that exceed max runtime
        while select workflowElementTable where workflowElementTable.DueDateTime < DateTimeUtil::getSystemDateTime()
        {
            workflowTable = SysWorkflowTable::find(workflowElementTable.CorrelationId);
            if (workflowTable.RecId && workflowTable.Version == WorkflowAXVersion::AX6)
            {
                // we need to post a message to WF runtime that causes it to take the action
                SysWorkflowQueue::elementDueDateExceeded(
                    workflowElementTable.CorrelationId,
                    workflowElementTable.ElementId,
                    workflowElementTable.MaxRuntimeId,
                    workflowElementTable.DueDateTime);
            }
            // Note if there is not a workflow instance record there is nothing we can do here the
            // batch will eat an exception workflow associated with the missing record will be in
            // an unrecoverable state - so we just fall through
        }
        select workflowNotificationStaging;
        if (workflowNotificationStaging)
        {
            notificationManager.run();
        }
    }
    ;
   
    info(strFmt("%1",time2str(timeNow(),1,1)));
    leaveTrans  = SAN_LeaveTrans::find("SAN_K-000054",true);
    recId       = leaveTrans.RecId;
    args.record(leaveTrans);
   
    argsCheck   = new Args();
    argsCheck.name(formStr(SAN_LeaveTransListPage));
    formRun     = classFactory.formRunClass(argsCheck);
    formRun.run();
    formRun.close();
    formRun.detach();
    args.caller(formRun);
   
    //Submit to workflow
    if(leaveTrans.canSubmitToWorkflow())
    {
        ttsbegin;
        note = "Workflow submitted for approval";
        workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName, recId, note, NoYes::No,curUserId());
        SAN_LeaveTrans::UpdateWorkflowState(recId,SAN_WorkflowState::PendingApproval);
        ttscommit;
        info("Done");
    }
    else
    {
        warning("Leave trans workflow cannot be submitted");
    }
    SAN_LeaveTransWFTypeSubmitManager::main(args); // Workflow submit manager class
 
 
    //Action auto Workflow
    select firstonly workitemTable
            where workitemTable.RefRecId == recId
                && workitemTable.RefTableId == 30034;
   
    elementTableRecId = WorkflowElementTable::find(workItemTable.ElementId).RecId;
    info(strFmt("%1",elementTableRecId));
   
    actionTable = WorkflowActionTable::findByAction(elementTableRecId,"Approve");
    info(strFmt("%1",actionTable.RecId,actionTable.Name));
    workflowservice = New SysWorkflowApprovalService();
    workflowservice.applyAction("Approve",workitemTable.Id,"testuser","SAN_i.com.kw","Leave Transaction Approved"); //Done for Approve and Reject
 
   //Cancel

    //Cancel workflow
   
    WorkflowCancelManager::cancelWorkflows(WorkflowCancelManager::getWorkflowsToCancel(args.caller()), note);
    cancel= SAN_LeaveTransWFTypeCancelManager::construct();
    cancel.run(args);
 
    SysWorkflow::cancel();
    SysWorkflow::cancelWorkflow();
   
    select firstonly workflowTablecheck
            where workflowTablecheck.InstanceNumber == "001587"
            && workflowTablecheck.ContextRecId == SAN_LeaveTrans::find("SAN_K-000057",true).RecId
            && workflowTablecheck.ContextTableId == tableNum(SAN_LeaveTrans)
            && workflowTablecheck.ContextCompanyId == curext()
            && workflowTablecheck.Category == WorkflowInstanceCategory::Workflow;
    if("Auto Cancel by ADMIN")
    {
        workflow::cancelWorkflow(workflowTablecheck.WorkflowCorrelationId,"Auto Cancel by ADMIN");
        info("Verified");
    }
 
    //Resubmit option by auto workflow
    while select WorkflowWorkItemTablechk
    where
        WorkflowWorkItemTablechk.UserId == 'testuser'
    &&  WorkflowWorkItemTablechk.Type == WorkflowWorkItemType::Recall
    &&  WorkflowWorkItemTablechk.Status == WorkflowWorkItemStatus::Pending
    &&  WorkflowWorkItemTablechk.RefTableId == tableNum(SAN_LeaveTrans)
    && WorkflowWorkItemTablechk.RefRecId == SAN_LeaveTrans::find("SAN_K-000057",true).RecId
    {
        WorkflowWorkItemTableins.clear();
        WorkflowWorkItemTableins.UserId = curUserId();
        WorkflowWorkItemTableins.Type = WorkflowWorkItemType::Recall;
        WorkflowWorkItemTableins.Status = WorkflowWorkItemStatus::Pending;
        WorkflowWorkItemTableins.RefRecId = WorkflowWorkItemTablechk.RefRecId;
        WorkflowWorkItemTableins.RefTableId = WorkflowWorkItemTablechk.RefTableId;
        WorkflowWorkItemTablechk.ActivityId = WorkflowWorkItemTablechk.ActivityId;
        WorkflowWorkItemTablechk.CommentId = WorkflowWorkItemTablechk.CommentId;
        WorkflowWorkItemTablechk.CompanyId = WorkflowWorkItemTablechk.CompanyId;
        WorkflowWorkItemTablechk.ConfigurationId = WorkflowWorkItemTablechk.ConfigurationId;
        WorkflowWorkItemTablechk.DataSourceName = WorkflowWorkItemTablechk.DataSourceName;
        WorkflowWorkItemTablechk.Description = WorkflowWorkItemTablechk.Description;
        WorkflowWorkItemTablechk.DocumentClassId = WorkflowWorkItemTablechk.DocumentClassId;
        WorkflowWorkItemTablechk.DueDateTime = WorkflowWorkItemTablechk.DueDateTime;
        WorkflowWorkItemTablechk.ElementId = WorkflowWorkItemTablechk.ElementId;
        WorkflowWorkItemTablechk.EscalationLevel = WorkflowWorkItemTablechk.EscalationLevel;
        WorkflowWorkItemTablechk.id = WorkflowWorkItemTablechk.id;
        WorkflowWorkItemTablechk.IsClaimed = WorkflowWorkItemTablechk.IsClaimed;
        WorkflowWorkItemTablechk.IsRead = WorkflowWorkItemTablechk.IsRead;
        WorkflowWorkItemTablechk.MenuItemName = WorkflowWorkItemTablechk.MenuItemName;
        WorkflowWorkItemTablechk.NotificationId = WorkflowWorkItemTablechk.NotificationId;
        WorkflowWorkItemTablechk.OriginalCorrelationId = WorkflowWorkItemTablechk.OriginalCorrelationId;
        WorkflowWorkItemTablechk.ParentCorrelationId = WorkflowWorkItemTablechk.ParentCorrelationId;
        WorkflowWorkItemTablechk.Queue = WorkflowWorkItemTablechk.Queue;
        WorkflowWorkItemTablechk.RootCorrelationId = WorkflowWorkItemTablechk.RootCorrelationId;
        WorkflowWorkItemTablechk.Subject = "Recall";
        WorkflowWorkItemTablechk.SubWorkflowId = WorkflowWorkItemTablechk.SubWorkflowId;
     
        WorkflowWorkItemTableins.insert();
        WorkflowWorkItemActionManager::dispatchWorkItemAction(
                                    WorkflowWorkItemTableins,
                                    "Auto Cancel by ADMIN", // comment
                                    'testuser', // << user ID
                                    WorkflowWorkItemActionType::Resubmit,
                                    "SAN_LeaveTransListPage", // << menu item action approval workflow
                                    false); //is not web Menu Item
        info("Verified");
    }
 
 
    doMessageProcessing();
   
    info(strFmt("%1",time2str(timeNow(),1,1)));
}

Clear Cache ax 2012

//Clear Cache ax Flush AOD ax 2012


SysFlushAOD::main(args);
SysFlushData::main(args);
SysFlushDictionary::main(args);
xSession::removeAOC();
SysTreeNode::refreshAll();
SysFlushDictionary::doFlush();
SysFlushAOD::doFlush();
xSession::updateAOC();

Workflow Helper Class ax 2012 -- Creation helper



SysWorkflowEventDispatcher-->onWorkItemCreate
SysWorkflowWorkItemContext
public server static WorkflowWorkItemInstanceId onWorkItemCreate(
    SysWorkflowWorkItemContext _workItemContext,
    WorkflowWorkItemClaimed _isClaimed = NoYes::Yes,
    NoYes _useAutoDelegatation = NoYes::Yes,
    WorkflowComment _comment = '')
{
    WorkflowTrackingMessage trackingMessage;
    SysWorkflowTracking tracking;
    WorkflowWorkItemTable workItem;
    WorkflowStepTable stepTable;
    WorkflowElementTable elementTable;
    WorkflowVersionTable versionTable;
    Map mergeValues = new Map(Types::String, Types::String);
    SysDictWorkflowElement sysDictWorkflowElement;
    WorkflowDocument workflowDocument;
    Query query;
    userId user;
    menuItemName menuItemName;
    EventNotificationWorkflow notification;
    WorkflowWorkItemInstanceId workItemId;
    WorkflowOutcomeName completingOutcome;
    WorkflowStepInstruction stepInstruction;
    WorkflowConfigMessageText subject;
    SysWorkflowTable workflowTable;
    WorkflowElementId elementId;
    WorkflowDateTime emptyDateTime;
    LabelId labelId;
    Struct trackingPropertyBag;
    List trackingMessageArgs;
    WorkflowUserList autoDelegators;
    #Workflow
    setprefix(classstr(SysWorkflowEventDispatcher) + '-' + staticmethodstr(SysWorkflowEventDispatcher, onWorkItemCreate));
    if (_workItemContext == null)
    {
        throw error(strfmt("@SYS104836", staticmethodstr(SysWorkflowEventDispatcher, onWorkItemCreate), varstr(_workItemContext)));
    }
    changecompany(_workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmCompanyId())
    {
        // create the work item
        versionTable = WorkflowVersionTable::find(_workItemContext.parmWorkflowCorrelation().parmWorkflowConfigurationKey().parmConfigurationId());
        workflowTable = SysWorkflowTable::find(_workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmWorkflowCorrelationId());
        if (workflowTable.RecId == 0)
        {
            throw error("@SYS116100");
        }
        user = _workItemContext.parmAxaptaUser();
        if (_useAutoDelegatation == NoYes::Yes)
        {
            autoDelegators = WorkflowUserList::construct();
            user = SysWorkflowHelper::getDelegate(_workItemContext.parmAxaptaUser(), versionTable);
            if (strcmp(user, _workItemContext.parmAxaptaUser()) != 0)
            {
                autoDelegators.add(_workItemContext.parmAxaptaUser());
            }
        }
        else
        {
            autoDelegators = _workItemContext.parmDelegators();
        }
        // These system generated work items are configured at the element level i.e. there is not
        // a step associated with them.
        if (_workItemContext.parmWorkItemType() == WorkflowWorkItemType::RequestChange ||
            _workItemContext.parmWorkItemType() == WorkflowWorkItemType::Return ||
            _workItemContext.parmWorkItemType() == WorkflowWorkItemType::FinalApprover)
        {
            elementTable = WorkflowElementTable::find(_workItemContext.parmElementId());
            if (elementTable.RecId == 0)
            {
                throw error("@SYS106828");
            }
            elementId = elementTable.ElementId;
            select firstonly StepId from stepTable where stepTable.ElementId == elementTable.ElementId && stepTable.Sequence == 1;
            if (!stepTable.StepId)
            {
                throw error("@SYS106826");
            }
            // Assign the step id of the element's first step to the system
            // created work item i.e.the resubmit work item is always associated
            // with the element's first step. A resubmit always restarts at the
            // element not the individual steps therefore the resubmit work item
            // is always associated with element's first step.
            _workItemContext.parmWorkStepId(stepTable.StepId);
            // Make sure we clear out the due date for these work item types
            if (_workItemContext.parmWorkItemType() == WorkflowWorkItemType::RequestChange ||
                _workItemContext.parmWorkItemType() == WorkflowWorkItemType::Return)
            {
                _workItemContext.parmDueDate(emptyDateTime);
            }
            // now that we have set the step id in the context we can get the delegate user
            sysDictWorkflowElement = new SysDictWorkflowElement(elementTable.ElementType, elementTable.ElementName);
            if (!sysDictWorkflowElement)
            {
                throw error (strfmt("@SYS110280", elementTable.ElementType, elementTable.ElementName));
            }
            if (_workItemContext.parmWorkItemType() == WorkflowWorkItemType::FinalApprover)
            {
                stepInstruction = SysWorkflowHelper::getLocalizedLabelText(literalstr("@SYS124600"), user);
                subject = SysWorkflowHelper::getLocalizedLabelText(literalstr("@SYS124601"), user);
            }
            else
            {
                stepInstruction = SysWorkflowHelper::getLocalizedLabelText(literalstr("@SYS110261"), user);
                subject = _workItemContext.parmWorkItemType() == WorkflowWorkItemType::RequestChange ?
                    SysWorkflowHelper::getLocalizedLabelText(literalstr("@SYS113435"), user) :
                    SysWorkflowHelper::getLocalizedLabelText(literalstr("@SYS112540"), user);
            }
            menuItemName = sysDictWorkflowElement.documentMenuItem();
            if (!SysWorkflowHelper::userHasPermission(
                _workItemContext.parmWorkflowCorrelation().parmWorkflowContext(),
                elementTable.workflowVersionTable().workflowTable().TemplateName,
                sysDictWorkflowElement.resubmitMenuItem(),
                menuItemName,
                user))
            {
                throw error(strfmt("@SYS109561", user));
            }
        }
        else
        {
            stepTable = WorkflowStepTable::find(_workItemContext.parmWorkStepId());
            if (!stepTable)
            {
                throw error("@SYS106826");
            }
            sysDictWorkflowElement = new SysDictWorkflowElement(stepTable.workflowElementTable().ElementType, stepTable.workflowElementTable().ElementName);
            if (!sysDictWorkflowElement)
            {
                throw error (strfmt("@SYS110280", stepTable.workflowElementTable().ElementType, stepTable.workflowElementTable().ElementName));
            }
            // the getXXXX methods do the language conversion
            stepInstruction = stepTable.getInstruction(user);
            subject = stepTable.getDescription(user);
            menuItemName = sysDictWorkflowElement.documentMenuItem();
            completingOutcome = sysDictWorkflowElement.getCompletingOutcome();
            if (!SysWorkflowHelper::userHasPermission(
                _workItemContext.parmWorkflowCorrelation().parmWorkflowContext(),
                stepTable.workflowElementTable().workflowVersionTable().workflowTable().TemplateName,
                sysDictWorkflowElement.actionMenuItem(completingOutcome),
                menuItemName,
                user))
            {
                throw error(strfmt("@SYS109561", user));
            }
        }
        ttsbegin;
        workItem.Id                 = newguid();
        workItem.ActivityId         = _workItemContext.parmWorkflowActivityInstanceKey().parmWorkflowActivityInstanceId();
        workItem.ConfigurationId    = _workItemContext.parmWorkflowCorrelation().parmWorkflowConfigurationKey().parmConfigurationId();
        workItem.DueDateTime        = _workItemContext.parmDueDate();
        workItem.CorrelationId      = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmWorkflowCorrelationId();
        workItem.ElementId          = _workItemContext.parmElementId();
        workItem.StepId             = _workItemContext.parmWorkStepId();
        workItem.RefTableId         = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmTableId();
        workItem.RefRecId           = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmRecId();
        workItem.CompanyId          = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmCompanyId();
        workItem.Type               = _workItemContext.parmWorkItemType();
        // approvals are always claimed, single task work items are always claimed.
        // When there is more than one work item for a task then all the work items are unclaimed - this is determined by the caller
        workItem.IsClaimed          = stepTable.workflowElementTable().ElementType == WorkflowElementType::Approval ? NoYes::Yes : _isClaimed;
        workItem.IsRead             = NoYes::No;
        workItem.Status             = WorkflowWorkItemStatus::Pending;
        workItem.SubWorkflowId      = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmSubWorkflowId();
        workItem.RootCorrelationId  = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmRootCorrelationId();
        workItem.ParentCorrelationId = _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmParentCorrelationId();
        workItem.EscalationLevel = 0;
        workItem.UserId = user;
        // verify that final approver is not the originator
        if (_workItemContext.parmWorkItemType() == WorkflowWorkItemType::FinalApprover &&
            sysDictWorkflowElement.type() == WorkflowElementType::Approval)
        {
            if (strcmp(workItem.UserId, workflowTable.Originator) == 0)
            {
                throw error(strfmt("@SYS119362", workflowTable.Originator));
            }
            if (strcmp(workItem.UserId, workflowTable.Submitter) == 0)
            {
                throw error(strfmt("@SYS126948", workflowTable.Submitter));
            }
            // Final approver: %1
            trackingMessage = strfmt("@SYS108731", workItem.UserId);
            labelId = literalstr("@SYS108731");
            trackingMessageArgs = new List(Types::Class);
            trackingPropertyBag = new Struct (#WorkflowTrackingArgumentStruct);
            trackingPropertyBag.value(#WorkflowTrackingArgumentDataType, extendedtypestr(WorkflowUser));
            trackingPropertyBag.value(#WorkflowTrackingArgumentValue, workItem.UserId);
            trackingMessageArgs.addEnd(trackingPropertyBag);
            tracking = SysWorkflowTracking::newSysWorkflowTracking(
                _workItemContext.parmWorkflowCorrelation(),
                workItem.UserId,
                WorkflowTrackingContext::Approval,
                WorkflowTrackingType::FinalApproverRequired);
            tracking.parmTrackingMessage(trackingMessage);
            tracking.parmElementId(elementId);
            tracking.parmName(elementTable.Name);
            tracking.parmMessageLabelId(labelId);
            tracking.parmMessageArgs(trackingMessageArgs);
            WorkflowTrackingTable::saveTracking(tracking);
        }
        workItem.Subject = WorkflowDocumentField::substitutePlaceholderAsUser(
            workItem.UserId,
            workItem.CompanyId,
            workItem.RefTableId,
            workItem.RefRecId,
            versionTable.workflowTable().TemplateName,
            versionTable.Owner,
            workflowTable.Originator,
            workItem.UserId,
            subject,
            _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmWorkflowCorrelationId());
        workItem.Description = WorkflowDocumentField::substitutePlaceholderAsUser(
            workItem.UserId,
            workItem.CompanyId,
            workItem.RefTableId,
            workItem.RefRecId,
            versionTable.workflowTable().TemplateName,
            versionTable.Owner,
            workflowTable.Originator,
            workItem.UserId,
            stepInstruction,
            _workItemContext.parmWorkflowCorrelation().parmWorkflowContext().parmWorkflowCorrelationId());
        if (!workItem.Description)
        {
            // if no descripton use the subject
            workItem.Description = subject;
        }
        workItem.DocumentClassId = className2Id(sysDictWorkflowElement.document());
        workItem.MenuItemName = menuItemName;
        workflowDocument = classfactory.createClass(className2Id(sysDictWorkflowElement.document()));
        if (!workflowDocument)
        {
            throw error("@SYS108554");
        }
        query = workflowDocument.getQuery();
        if (!query)
        {
            throw error("@SYS96001");
        }
        workItem.DataSourceName = sysDictWorkflowElement.documentFormDatasourceName();
        // notify the assignee
        notification = EventNotificationWorkflow::newAction(
            workItem.UserId,
            workItem.Subject,
            DateTimeUtil::date(workItem.DueDateTime),
            workItem.getMenuFunction(),
            workItem.getRecord(),
            WorkflowParameters::find().WorkItemEmailId,
            mergeValues,
            workItem.Description,
            workItem.DataSourceName);
        workItem.NotificationId = notification.create();
        workItem.insert();
        // Assigned to: %1. Due date %2
        trackingMessage = strfmt("@SYS108739", workItem.UserId, _workItemContext.parmDueDate());
        labelId = literalstr("@SYS108739");
        trackingMessageArgs = new List(Types::Class);
        // add user arg
        trackingPropertyBag = new Struct (#WorkflowTrackingArgumentStruct);
        trackingPropertyBag.value(#WorkflowTrackingArgumentDataType, extendedtypestr(WorkflowUser));
        trackingPropertyBag.value(#WorkflowTrackingArgumentValue, workItem.UserId);
        trackingMessageArgs.addEnd(trackingPropertyBag);
        // add due date arg
        trackingPropertyBag = new Struct (#WorkflowTrackingArgumentStruct);
        trackingPropertyBag.value(#WorkflowTrackingArgumentDataType, extendedtypestr(WorkflowDueDate));
        if (_workItemContext.parmWorkItemType() == WorkflowWorkItemType::FinalApprover &&
            sysDictWorkflowElement.type() == WorkflowElementType::Approval)
        {
            trackingPropertyBag.value(#WorkflowTrackingArgumentValue, DateTimeUtil::toStr(DateTimeUtil::minValue()));
            trackingPropertyBag.value(#WorkflowTrackingArgumentDate, DateTimeUtil::minValue());
        }
        else
        {
            trackingPropertyBag.value(#WorkflowTrackingArgumentValue, DateTimeUtil::toStr(_workItemContext.parmDueDate()));
            trackingPropertyBag.value(#WorkflowTrackingArgumentDate, _workItemContext.parmDueDate());
        }
        trackingMessageArgs.addEnd(trackingPropertyBag);
        tracking = SysWorkflowTracking::newSysWorkflowTracking(
            _workItemContext.parmWorkflowCorrelation(),
            workItem.UserId,
            WorkflowTrackingContext::WorkItem,
            WorkflowTrackingType::Creation);
        tracking.parmTrackingMessage(trackingMessage);
        tracking.parmTrackingComment(_comment);
        tracking.parmWorkItemId(workItem.Id);
        tracking.parmWorkItemActivityInstanceId(workItem.ActivityId);
        tracking.parmElementId(workItem.ElementId);
        tracking.parmStepId(workItem.StepId);
        tracking.parmDueDate(workItem.DueDateTime);
        tracking.parmMessageLabelId(labelId);
        tracking.parmMessageArgs(trackingMessageArgs);
        WorkflowTrackingTable::saveTracking(tracking);
        SysWorkflowEventDispatcher::trackWorkItemDelegation(_workItemContext, workItem, autoDelegators);
        ttscommit;
        workItemId = workItem.Id;
    }
    return workItemId;
}

Running the report via code Without controller

//Running the report via code WO controller

static void ReportRunCheck(Args _args)
{
    SrsReportRunController      reportRunController;
    Map                         queryContracts;
    MapEnumerator               mapEnum;
    Query                       query;
    QueryBuildRange             range;
    SrsReportDataContract       contract;
    FCCPaySlipContract   rdpContract;
    FilePath                    outputPath = "c:\\";
    ;
    reportRunController = new SrsReportRunController();
    reportRunController.parmReportName('FCCPAYLIP.Report');
    reportRunController.parmLoadFromSysLastValue(false);
   
    contract    = reportRunController.parmReportContract();
    contract.parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    contract.parmPrintSettings().overwriteFile(true);
    contract.parmPrintSettings().fileFormat(SRSReportFileFormat::XML);
    contract.parmPrintSettings().fileName(outputPath + "Payslip.xml");
  
    rdpContract = contract.parmRdpContract() as FCCPaySlipContract;
    rdpContract.parmEmployeeId("2005");
    rdpContract.parmPayMonth(mkDate(01,06,2016));   
   
    //queryContracts = contract.parmQueryContracts();
    //mapEnum = queryContracts.getEnumerator();
    //while(mapEnum.moveNext())
    //{
        //query = mapEnum.currentValue();
        //range = SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(VendTable)),fieldNum(VendTable,AccountNum));
        //range.value('3*');
    //}
   
    reportRunController.runReport();
}

Read Image from AX to web service AIF .Net

//Read Image from AX to web service AIF .Net

public str  GetEmplImage(Description employeeId)
{
    str             content;
   
   XmlDocument  getImageXml(Description _employeeId)
   {
        XmlDocument xmlEnvelope;
        XmlElement childNode;
        str contentloc;
        HcmWorker       worker;
        HcmPersonImage  PersonImage;
  
        CompanyImage ci;
  
         BinData bin = new BinData();       
        worker = HcmWorker::findByPersonnelNumber(_employeeId);
   
        select firstOnly PersonImage
                where PersonImage.Person == worker.Person;
      
        bin.setData(PersonImage.Image);
        contentloc = bin.base64Encode();
        xmlEnvelope = new XmlDocument();
        childNode =  xmlEnvelope.CreateElement("image");
        childNode.innerXml(contentloc);
        xmlEnvelope.AppendChild(childNode);
        return xmlEnvelope;
    }
    ;   
    content = getImageXml(employeeId).xml();
    return content;
}

SSRS Report Timeout issue ax 2012

//SSRS Timeout issue ax 2012

Source;

http://axmentor.com/learning-lab/blog/reporting/how-to-fix-ssrs-timeouts-in-ax-2012-the-right-way/

Upgrade Paths AX Application

//Upgrade Paths AX Application


https://technet.microsoft.com/en-us/library/dd362093.aspx

Refresh and reread reference Datasource

//Refresh and reread reference Datasource

mainAccount_ds.rereadReferenceDataSources();

Auto Generate Item Barcode in ax 2012

//Auto Generate Barcode in ax 2012
public static void main(Args _args)
{
    InventItemBarcode   barcode, argBarcode;
    InventDim           inventDim, barcodeInventDim;
    EcoResDistinctProductVariant EcoResDistinctProductVariant;
    InventDimCombination InventDimCombination, comb;
    InventTable inventTable;
    str itemBarcode;

    InventTable = _args.record();

    while select EcoResDistinctProductVariant where EcoResDistinctProductVariant.ProductMaster == InventTable.product
        join InventDimCombination where InventDimCombination.DistinctProductVariant == EcoResDistinctProductVariant.RecId
            join inventDim where inventDim.inventDimId == InventDimCombination.InventDimId
    {

        itemBarcode = "";
        if (InventDimCombination)
        {
            barcodeInventDim.clear();
            barcodeInventDim.InventSizeId = InventDimCombination.inventDim().InventSizeId;
            barcodeInventDim.InventColorId = InventDimCombination.inventDim().InventColorId;
            barcodeInventDim.InventStyleId = InventDimCombination.inventDim().InventStyleId;
            barcodeInventDim.configId = InventDimCombination.inventDim().ConfigId;
            barcodeInventDim = inventDim::findOrCreate(barcodeInventDim);
            barcode.clear();
            barcode.initValue();
            barcode.itemId = InventTable.ItemId;
            barcode.initFromItemId();
            barcode.RetailVariantId = InventDimCombination.RetailVariantId;
            barcode.inventDimId = barcodeInventDim.inventDimId;
            barcode.barcodeSetupId = EcoResProductParameters::find().Fcc_BarcodeSetupId;
            barcode.useForInput = NoYes::Yes;
            barcode.useForPrinting = NoYes::Yes;
            barcode.description = InventDimCombination.defaultProductName();
            if(barcodeInventDim.InventSizeId != "" && barcodeInventDim.InventColorId != "")
            {
                itemBarcode = strFmt("%1-%2-%3",inventTable.ItemId,barcodeInventDim.InventSizeId, barcodeInventDim.InventColorId);
            }
            else
                if (barcodeInventDim.InventSizeId != "" && barcodeInventDim.InventColorId == "")
                {
                    itemBarcode = strFmt("%1-%2",inventTable.ItemId,barcodeInventDim.InventSizeId);
                }
            else
                if (barcodeInventDim.InventSizeId == "" && barcodeInventDim.InventColorId != "")
                {
                     itemBarcode = strFmt("%1-%2",inventTable.ItemId,barcodeInventDim.InventColorId);
                }
            barcode.itemBarCode = itemBarcode;
            if (barcode.validateWrite())
            barcode.insert();
        }
    }

}

Compilation without compiler window ax 2012

//Compilation without compiler window ax 2012

static void SysCompilerTargetExample(Args _args)
{
    ClassBuild          classBuild;
    DictClass           dictClass;
    SysCompilerTarget   targetOrig;
    ;
    // Setting Compilation Target = Message Window
    targetOrig = SysUserInfo::compilerTarget();
    SysUserInfo::compilerTarget(SysCompilerTarget::MessageWindow);
    SysCompilerOutput::setCompilerTarget(SysCompilerTarget::MessageWindow);
    SysCompilerOutput::updateParm();

    // Building the class with 1 method
    classBuild = new ClassBuild("TRN_ClassBuild", false);
    classBuild.addMethod("test", 'void test()\n{\n}');
    classBuild.addSourceToMethod("test", @"
    ;
    info('We created a Class and can call its methods');");

    // The actual compilation. Note the _flag argument == 1
    classBuild.classNode().AOTcompile(1);

    // Call the class method to show that we are done and the code is compiled
    dictClass = new DictClass(className2Id(classBuild.name()));
    dictClass.callObject('test', dictClass.makeObject());

    // Restoring Compilation Target to its original value
    SysUserInfo::compilerTarget(targetOrig);
    SysCompilerOutput::setCompilerTarget(targetOrig);
    SysCompilerOutput::updateParm();
}

Batch Server to Execute Batch Job

//Batch Server to Execute Batch Job
xApplication::checkForNewBatchJobs();
xApplication::stopBatch();
https://msdn.microsoft.com/en-us/library/xapplication.aspx

Update GL posted Voucher number ax 2012

//Update GL posted Voucher ax 2012

//Change Field name as per requirement

//CustTrans/VendTrans/AssetTrans / ledgerTrans Sample

LedgerJournalTrans          jourTrans;
    CustTrans           custTrans; //00000003ST-
    GeneralJournalEntry jouranlEntry;
    SubledgerVoucherGeneralJournalEntry linkVOucher;
    ;
    update_recordSet jourTrans setting Voucher = "ST-00000003"
        where jourTrans.Voucher == "00000003ST-";
    update_recordSet custTrans setting Voucher = "ST-00000003"
        where custTrans.Voucher == "00000003ST-";
    update_recordSet jouranlEntry setting SubledgerVoucher = "ST-00000003"
        where jouranlEntry.SubledgerVoucher == "00000003ST-";
   
    update_recordSet linkVOucher setting Voucher = "ST-00000003"
        where linkVOucher.Voucher == "00000003ST-";


//Project Trans

    LedgerJournalTrans          jourTrans;
    GeneralJournalEntry jouranlEntry;
    SubledgerVoucherGeneralJournalEntry linkVOucher;
    LedgerJournalTrans_Project  transProject;
    ProjTransPosting        projTrans;
    ProjCostTrans   projCostTrans;
    TransDate       _date= mkDate(01,02,2016);
    ;
     jourTrans.clear();
    update_recordSet jourTrans setting TransDate = _date
        where jourTrans.Voucher == "00028/2016";
    jourTrans.clear();
    transProject.clear();
    update_recordSet transProject setting ProjTransDate = _date
        where transProject.RefRecId == jourTrans.RecId
            join jourTrans
                where jourTrans.Voucher == "00028/2016"
                    && jourTrans.AccountType == LedgerJournalACType::Project;
    projTrans.clear();
    update_recordSet projTrans setting ProjTransDate = _date,LedgerTransDate = _date,PaymentDate =_date
        where projTrans.Voucher == "00028/2016";
   
    projCostTrans.clear();
    jourTrans.clear();
    transProject.clear();
    while select jourTrans
        where jourTrans.Voucher == "00028/2016"
           && jourTrans.AccountType == LedgerJournalACType::Project
           join transProject
                where  transProject.RefRecId == jourTrans.RecId
    {
        ttsBegin;
        while select forupdate projCostTrans
                where projCostTrans.TransId == transProject.TransId
        {
            projCostTrans.TransDate = _date;
            projCostTrans.update();
            info(strFmt("%1,%2,%3",projCostTrans.TransDate,projCostTrans.TransId,projCostTrans.RecId));
        }       
        ttsCommit;
    }

    jouranlEntry.clear();
    update_recordSet jouranlEntry setting AccountingDate = _date
        where jouranlEntry.SubledgerVoucher == "00028/2016";
    linkVOucher.clear();
    update_recordSet linkVOucher setting AccountingDate = _date
        where linkVOucher.Voucher == "00028/2016";

AX Roles tips

//AX Roles
//For FA Module
1) Export all duties which start with "Asset*"
//For GL Module
1) Duty --> LedgerChartOfAccountsInquire,LedgerChartOfAccountsMaintain
     LedgerJournalsAndTransactionsMaintain,LedgerGeneralLedgerProcessPerfReview
//Workflow
Privileges
Maintain quered work items
Maintain work item queues
Workflow approval service apply action operation
Workflow approval service get work items operation
Worfklow approval tasks for the purchase order header
Workflow essentials
//WOrklfow Purchase order approval
//Approve Purchase Order -- DUty(PurchOrderApprove)

//For all Workflow approval element
1) Export all Privileges which start with "Approve*"

Error: Cannot create a record in Relation between purchase lines and request for Quotation lines (PurchOrderRFQLineReference)

// Error:
 Cannot create a record in Relation between purchase lines and request for Quotation lines (PurchOrderRFQLineReference)

Resolution:

static void CheckRFQPo(Args _args)
{
    VendRFQTrans               vendRFQTrans;
    PurchRFQLine               purchRFQLine;
    PurchRFQCaseLine           purchRFQCaseLine;
    PurchLine                   purchLine;
    PurchOrderRFQLineReference purchOrderRFQLineReference;
    int i;
    ;
    //select firstonly vendRFQTrans
        //where vendRFQTrans.Status  == PurchRFQStatus::Accepted
        //join rfqCaseLineRefRecId from purchRFQLine
        //where purchRFQLine.LineNum == vendRFQTrans.LineNum
            //&& purchRFQLine.rfqId   == vendRFQTrans.rfqId
        //exists join purchRFQCaseLine
        //where purchRFQCaseLine.RecId        == purchRFQLine.rfqCaseLineRefRecId
            ////&& purchRFQCaseLine.ReqLineRefId == "{DA03C50D-7458-48B4-9387-BF20108FC2BD}"
            //&& purchRFQCaseLine.rfqCaseId    == "000008"
            //&& purchRFQCaseLine.DataAreaId   == "dat";
//
    //info(strFmt("%1",vendRFQTrans.RecId));
   
    ttsBegin;
    while select forUpdate purchOrderRFQLineReference
            //where purchOrderRFQLineReference.VendRFQTrans == 5637146087
    {
        if(purchOrderRFQLineReference.PurchLineDataAreaID != curext())
        {
            changeCompany(purchOrderRFQLineReference.PurchLineDataAreaID)
            {
                purchLine = PurchLine::findInventTransId(purchOrderRFQLineReference.PurchLineInventTransId,false);
                if(!purchLine)
                {
                    purchOrderRFQLineReference.delete();
                    i++;
                }
            }
           
        }
        else
        {
            purchLine = PurchLine::findInventTransId(purchOrderRFQLineReference.PurchLineInventTransId,false);
            if(!purchLine)
            {
                purchOrderRFQLineReference.delete();
                i++;
            }
        }
       
    }
    info(strFmt("No of record deleted %1",i));
    ttsCommit;
}

Error on Update Table Record (While table enable : ValidTimeStateUpdateMode)

//Update Table Record (enable : ValidTimeStateUpdateMode)

Cannot edit a record in <Table>. Update on a valid time state table is not allowed without specifying a ValidTimeStateUpdateMode.

TableName.ValidTimeStateUpdateMode(ValidTimeStateUpdate::Correction);

Increase or decrease dialog size

dlgCustAccount.heightMode(<Integer>);
 dlgCustAccount.widthMode(<Integer>);

dialog.formBuildDesign().height(<Integer>);
 dialog.formBuildDesign().width(<Integer>);

dlgCustAccount.displayHeight();
dlgCustAccount.displayWidth();

Microsoft Azure Server Deployment

//Microsoft Azure Server Deployment

https://ax.help.dynamics.com/en/wiki/deploy-a-test-environment-on-azure/



https://blog.pa.com.au/cfo/4-reasons-to-run-microsoft-dynamics-ax-2012-r3-on-azure/
https://blogs.msdn.microsoft.com/axsupport/2014/05/11/ax-content-deploy-ax-2012-r3-on-azure/
https://stoneridgesoftware.com/dynamics-ax-2012-r3-demo-environments-on-windows-azure/
https://ax.help.dynamics.com/en/wiki/plan-your-microsoft-dynamics-ax-2012-r3-deployment-on-azure/

Get Multiple return list class from ax in .Net

//Get Multiple return list class from ax in .Net

getTransMsg = clien.CreatePayment(context, parm);
if (getTransMsg != null && getTransMsg.Length > 0)
{
   foreach (ServiceReference1.ClsAXTransactionMessage item in getTransMsg)
   {
       MessageBox.Show(item.AxDocDocumentNo);
       MessageBox.Show(item.StatusMessage);
       MessageBox.Show(item.SuccesFlag.ToString());
   }

Import Financial Dimension Definition in AX Standard Class

//To Import Financial Dimension Definition in AX Standard Class

class--> LedgerFinancialStmtImport_ES_->Run


Class->>LedgerAcctsFinancialStmtImport

Import MainAccount using AX Standard Class

//To Import MainAccount in AX Standard Class

Refer Below Classes

Class-->LedgerAcctsImport_ES-->Method -->Run


Calling class
Clas--> LedgerAcctsFinancialStmtImport

Set and Validate Field in AX

//Set and Validate Field in AX

protected void setAndValidateField(Common _buffer, str _value, fieldId _fieldId)
{
    _buffer.(_fieldId) = this.convertToFieldType(_buffer, _value, _fieldId);
    if (!_buffer.validateField(_fieldId))
    {
        this.exceptionOccured();
    }
}

Convert Call stack to readable format in D365FO X++

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