Thursday 4 December 2014

Get list of all Projects in AOT

There's many times when we tend to get the list of all the projects existing in the AOT. This is helpful to keep the development documentation up-to-date. The code below provides an easy list of all the projects and saves them in a csv file.

static void GetProjectNames(Args _args)

{
    #AOT
    #File
    #Properties
   
    TextIo csvIO;
    str description;
    TreeNode projects;
    int total, counter;
  ; 
    csvIO = new TextIo(@"C:\HBProjectsList.xls", #IO_WRITE);
    csvIO.write("Project Name\n");
    projects = TreeNode::findNode(@"\Projects\Shared");
   
    total = projects.AOTchildNodeCount();
    projects = projects.AOTfirstChild();
   
    info(int2str(Total));
   
    for(counter = 1; counter <= total; counter++)
    {
        description += projects.AOTname();
        description += "\n";
        projects = projects.AOTnextSibling();
    }
   
    csvIO.write(description);
}

Sunday 19 October 2014

DIXF / DMF Issue with Entities

Using DIXF requires a set of versatile skills from Excel to X++. I came across this issue where I kept getting the error below every time I uploaded various entities particularly Customer.

Results. Record ('XXX') . A record with RecId 0 does not exist.
Results. Record ('XXX') . Account  does not exist.
Results. Record ('XXX') . Update has been cancelled.
This issue was caused by incorrect lincence configuration when a field was passed on and the key was not enabled. Below code can be used to clean the data in the staging on the fly.
static void CLearCustomerEntityState(Args _args)
{
    DMFCustomerEntity cust;
    int counter;
    ;
        counter = 0;
    while select forUpdate cust where cust.TransferStatus == 2
    {
        ttsBegin;
             cust.State = "";
             cust.County = "";
        cust.AccountBalance = 0;
        cust.update();
        ttsCommit;

        counter++;
    }
    info(strFmt("Cleared : %1",counter));

}

Wednesday 15 October 2014

Create Security Roles Using X++

There is times when we need to create security roles in a good number particularly to deal with workflow. The below code would do the job just well.

static void InsertSecurityRoles(Args _args)
{
SecurityRole role;
;
 ttsBegin;
  
        select forUpdate role;
        role.Name='SEC_Group'; 
        role.AOTName='SEC_Group'; 
        role.description='Description of the security role'; 
        role.insert();
 ttsCommit;

info("Groups Created");
}