Tuesday, 26 April 2016

How to Get What are customizations are done in Var Layer Ax 2012


  • Create a new Project in Shared Folder

  • Then click on Filter, then a form will appear
  • In Grouping, Click on AOT 
  • Then Click on Select




















  • In SysModelLayer, Select Var Layer and Click Ok.
  • Now Click Ok in Project filter form
  • Now you can check What are the Customization are done in Var Layer that will attach to ur project folder

Encrypt and Decrypt Passwords using X++ in Ax 2012


  • Create a Class
  • In Properties Change the Property Runon : Server
In main method write the following code


public static void main(Args args)

{
    CryptoApi                           cryptoApi;
    Container                           cont,cont1;
    ContainerClass                      containerClass;
    ;

   /* Salt is like a password, While encrypting and descrypting the phrase, the CryptoAPI class has to instantiated with same salt(123456).
   The phrases/words are encrypted & decrypted based on the salt. */

    cryptoApi = new CryptoApi(123456);
    containerClass = new ContainerClass(["Rajendra"]);
    cont = CryptoApi.encrypt(containerClass.toBlob()); // The encrypt method requires BLOB as a parameter
    
    cont1 = ContainerClass::blob2Container(CryptoApi.decrypt(cont));
    info(Strfmt("Encrypted:  %1",BinData::dataToString(cont)));
    info(con2str(cont1));
}

Monday, 18 April 2016

How to get Server and Data Base Name through X++ Code in Ax 2012

static void Raj_Server_DataBaseName(Args _args)
{
    str               database,servername;

    database        =   SysSQLSystemInfo::construct().getloginDatabase();
    servername   =   SysSQLSystemInfo::construct().getLoginServer();

    info(strFmt("ServerName - %1  Data Base -- %2",servername,database));

}

 For DomainName and Username

static void Raj_DomainNameUserName(Args _args)
{
    InteropPermission   permission;
    str                 userName;
    str                 userDomain;
    ;
    permission = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();
    userDomain  = System.Environment::get_UserDomainName();
    userName    = System.Environment::get_UserName();
    info(strFmt(@"%1\%2", userDomain, userName));
}

How to Change Background color of Dynamics Ax

 Class Name : SysSetupFormRun

 Override the run method with following code

 public void run()
 {
     ;
     super();
     switch(curext())
     {
            case "USMF":
            this.design().colorScheme(FormColorScheme::RGB);
            this.design().backgroundColor(WinAPI::RGB2int( 204,255,0));  
            break;
            
           case "DAT":
           this.design().colorScheme(FormColorScheme::RGB);
           this.design().backgroundColor(WinAPI::RGB2int (155,255,0));
           break;
      }
   }


// For a Individual Form
  • Design your own form or existing form 
  • Override run Method and following code

     public void run()
    {
        super();
       this.design().colorScheme(FormColorScheme::RGB);
    
       this.design().backgroundColor(WinAPI::RGB2int (155,255,0));
    
    }

//to change the background color of a form by company



Monday, 11 April 2016

AND OR operation in DynamicQuery Ax 2012

static void AddORRangeToQuery(Args _args)
{
    Query q = new Query();  // Create a new query.
    QueryRun qr;
    CustTable ct;
    QueryBuildDataSource qbr1;
    str strTemp;
    ;

   
    qbr1 = q.addDataSource(tablenum(CustTable));
    // Name the datasource 'Customer'.
    qbr1.name("Customer");

    // Create a range value that designates an "OR" query like:
                                                // customer.AccountNum == "4000" || Customer.CreditMax > 2500.

        qbr1.addRange(fieldNum(CustTable, AccountNum)).value(strFmt('((%1.%2 == "4000") || (%1.%3 > 2500))',
        qbr1.name(),
        fieldStr(CustTable, AccountNum),
        fieldStr(CustTable, CreditMax)));

      
    // Print the data source.
    print qbr1.toString();
    info(qbr1.toString());

    
}


--> Replace OR operator with AND operator it will work as AND Operator in DynamicQuery.

AND

static void AddORRangeToQuery(Args _args)
{
    Query q = new Query();  // Create a new query.
    QueryRun qr;
    CustTable ct;
    QueryBuildDataSource qbds;
    QueryBuildRange      qbr1;
    str strTemp;
    ;

   qbds = q.addDataSource(tableNum(CustTable));
   qbr1  = qbds.addRange(fieldNum(CustTable, AccountNum));
   qbr1.value('4000');
   qbr1  = qbds.addRange(fieldNum(CustTable,CustGroup));
   qbr1.value('10');
    
   info(qbds.toString());

}



How to create XML through code in ax 2012

STATIC void Raj_XMLCreation()
{
    XmlDocument xmlDoc;
    XmlElement xmlRoot;
    XmlElement xmlField;
    XmlElement xmlRecord,xmlRecord1,xmlRecord2;
    XMLWriter xmlWriter;
    CustPackingSlipTrans custPackingSlipTrans;
    SalesLine salesLine_1;
    CustPackingSlipJour custPackingSlipJour;
    DictTable dictTable_1 = new DictTable(tablenum(SalesLine));
    DictTable dictTable_2 = new DictTable(tablenum(CustPackingSlipJour));
    DictTable dictTable_3 = new DictTable(tablenum(CustPackingSlipTrans));
    DictField dField;
    int i, fieldId,fieldid_1;
    str value;
    FileIoPermission _perm;
    PackingSlipId _packingSlipId;
    ;

    xmlDoc = XmlDocument::newBlank();
    xmlRoot = xmlDoc.createElement("CustPackingSlip");
    _packingSlipId = "SPK-000001";

    select custPackingSlipJour where  custPackingSlipJour.PackingSlipId == _packingSlipId;

    while select salesline_1 where salesLine_1.SalesId == custPackingSlipJour.SalesId
    {
        select CustPackingSlipTrans
            where CustPackingSlipTrans.PackingSlipId == custPackingSlipJour.PackingSlipId && CustPackingSlipTrans.SalesId == salesLine_1.SalesId && CustPackingSlipTrans.InventTransId == salesLine_1.InventTransId;

        xmlRecord1 = xmlDoc.createElement("SalesLine");
            for (i=1; i<=5; i++)
            {
                switch(i)
                {
                    case 1:
                        fieldId = fieldname2id(salesLine_1.TableId,"LineNum");
                        break;
                    case 2:
                        fieldId = fieldname2id(salesLine_1.TableId,"ItemId");
                        break;
                    case 3:
                        fieldId = fieldname2id(salesLine_1.TableId,"SalesQty");
                        break;
                    case 4:
                        fieldId = fieldname2id(salesLine_1.TableId,"SalesUnit");
                        break;
                    case 5:
                        fieldId = fieldname2id(salesLine_1.TableId,"RemainSalesPhysical");
                        break;

                }
                dField = dictTable_1.fieldObject(fieldId);
                xmlField = xmlDoc.createElement(dField.name());
                value = salesLine_1.(fieldId);
                xmlField.innerText(value);
                xmlRecord1.appendChild(xmlField);
            }
       xmlRecord2 = xmlDoc.createElement("CustPackingSlipJour");
       xmlRecord = xmlDoc.createElement("CustPackingSlipTrans");
            for (i=1; i<=3; i++)
            {
                switch(i)
                {
                    case 1:
                        fieldId = fieldname2id(CustPackingSlipTrans.TableId,"PackingSlipId");
                        break;
                    case 2:
                        fieldId = fieldname2id(CustPackingSlipTrans.TableId,"Remain");
                        break;
                    case 3:
                        fieldId = fieldname2id(CustPackingSlipTrans.TableId,"Qty");
                        break;
                }

            dField = dictTable_3.fieldObject(fieldId);
            xmlField = xmlDoc.createElement(dField.name());
            switch (dField.baseType())
            {
                case Types::Int64 :
                    value = int642str(CustPackingSlipTrans.(fieldId));
                    break;
                case Types::Integer :
                    value = int2str(CustPackingSlipTrans.(fieldId));
                    break;
                default :
                    value = CustPackingSlipTrans.(fieldId);
                break;
            }
            xmlField.innerText(value);
            xmlRecord.appendChild(xmlField);

            if(value != "" && fieldId == fieldname2id(CustPackingSlipTrans.TableId,"PackingSlipId"))
            {
                fieldId_1 = fieldname2id(custPackingSlipJour.TableId,"Qty");
                dField = dictTable_2.fieldObject(fieldId_1);
                xmlField = xmlDoc.createElement(dField.name());
                value = custPackingSlipJour.(fieldId_1);
                xmlField.innerText(value);
                xmlRecord2.appendChild(xmlField);

            }
            else if((value == "" && fieldId == fieldname2id(CustPackingSlipTrans.TableId,"PackingSlipId")))
            {
                fieldId_1 = fieldname2id(custPackingSlipJour.TableId,"Qty");
                dField = dictTable_2.fieldObject(fieldId_1);
                xmlField = xmlDoc.createElement(dField.name());
                value = custPackingSlipJour.(fieldId_1);
                xmlRecord2.appendChild(xmlField);

            }
            }
        xmlrecord2.appendChild(xmlRecord);
        xmlrecord1.appendChild(xmlRecord2);
        xmlRoot.appendChild(xmlRecord1);
    }
    xmlDoc.appendChild(xmlRoot);
    info(xmlDoc.toString());
      xmlWriter = XMLWriter::newFile(@"C:\Users\rajendra.c\Desktop\"+custPackingSlipJour.PackingSlipId+".xml");
    xmlDoc.writeTo(xmlWriter);

}

Wednesday, 6 April 2016

How to count no.of Methods and display the method names in a class using X++ Code

static void Raj_CountMethodsinClass(Args _args)
{

    SysDictClass sysDictClass  = new SysDictClass(481);// Provide the ClassID
    TreeNode    treeNode = TreeNode::findNode(sysDictClass.path());
    TreeNode    childNode;
    Counter     counter = 1;

    if (treeNode)
    {
        info(strfmt('Number of methods in the class: %1',treeNode.aotchildnodecount()));
        childnode = treenode.aotfirstchild();
        while(counter <= treeNode.aotchildnodecount())
        {
            info(childNode.treeNodeName()); //Print the methods name
            //info(childNode.AOTgetSource()); Uncomment this to print the coding of the method
            childNode = childNode.aotnextsibling();
            counter++;
        }
    }
}

Tuesday, 5 April 2016

How to find specific EDT in Tables using X++ Code

static void Raj_findEdtinTable(Args _args)
{

    treeNode childNode;
    treeNode fields;
    treenodeIterator it, itFld;

    str properties;
    str table;
    str field;
    str extendedDataType;
    str searchType = "PurchInternalInvoiceId";     // EDT
    int x;
    treeNode t  = TreeNode::findNode('\\Data Dictionary\\Tables');
    ;

    it = t.AOTiterator();
    childNode= it.next();
    while (childNode)
    {
      Table = childNode.treeNodeName();
      itFld = t.AOTfindChild(childNode.treeNodeName()).AOTfindChild("Fields").AOTiterator();

      fields = itFld.next();
      while (fields)
      {
        field = fields.treeNodeName();
        properties = fields.AOTgetProperties();
        extendedDataType = findProperty(properties, "ExtendedDataType");

        if (extendedDataType == searchType)
        {
          info(strfmt("%1 / %2 – ExtendedDataType: %3", table, field, extendedDataType));
        }
        fields = itFld.next();
      }
      childNode= it.next();
    }

}