Sunday, March 6, 2016

Delete AOT Object via Code X++

// Delete AOT Object via Code X++

//Sample 1
tatic void TestJob_San(Args _args)
{
    #AOT
    TreeNode treeNode;
    TreeNode treeNodeTable; ;
    treeNode = TreeNode::findNode(#JobsPath);
    treeNodeTable = treeNode.AOTfindChild('Job1');
    treeNodeTable.AOTdelete();
}

//Sample 2
static void DeleteTables(Args _args)
{
    TreeNode tree1, tree2;
    ;
    tree1 = TreeNode::findNode("Data Dictionary\\Tables");
    if (tree1 != null)
    {
        tree2 = tree1.AOTfindChild("tablename");
        if (tree2 != null)
        {
            tree2.AOTdelete();
        }
    }
}

//Sample 3
static void Job1(Args _args)
{
    UtilIdElements utilElement;
    ;
    ttsbegin;
    select utilElement
        where utilElement.name == 'myElementName'
        && utilElement.utilLevel == utilEntryLevel::cus // any layer
        && utilElement.recordType == utilElementType::Table; // object type
    if (utilelement)
    {
        utilElement.delete();
        ttscommit;
        info('Record should be deleted now.');
    }
    else
    {
        ttsAbort;
        info('Could not delete record, or it was not found.');
    }
}

Dimension Create Default Dimension

DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault result;
    int i;
    DimensionAttribute dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
    container conAttr = ["BusinessUnit","Department" ,"Project"];
    container conValue;
    str dimValue;
conValue = ["", "", reqLine.ProjId];
            dimValue = "";
            i = 0;
            for (i = 1; i <= conLen(conAttr); i++)
            {
                dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
                if (dimensionAttribute.RecId == 0)
                {
                    continue;
                }
                dimValue = conPeek(conValue,i);
                if (dimValue != "")
                {
                    dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
                    valueSetStorage.addItem(dimensionAttributeValue);
                }
            }
            result = valueSetStorage.save();

SQL ODBC Connection to another DB

//SQL ODBC Connection to another DB
static void SQLODBCConnection(Args _args)
{
    OdbcConnection con;
    SqlSystem       sq;
    LoginProperty   loginProperty;
    Statement statement1;
    ResultSet myResult1;
    str sqlStmnt;
    SqlStatementExecutePermission perm;
    sq = new SqlSystem();
    loginProperty = new LoginProperty();
    loginProperty.setServer("AOSSERVER");
    loginProperty.setDatabase("MicrosoftDynamicsAX");
    con = new OdbcConnection(loginProperty);
    sqlStmnt = strFmt("select * from Fcc_BankChequeMenus"); //write your query here
    statement1 = con.createStatement();
    perm = new SqlStatementExecutePermission(sqlStmnt);
    perm.assert();
    myResult1  = statement1.executeQuery(sqlStmnt);
    while(myResult1.next())
    {
        info(myResult1.getString(4));
        info(myResult1.getString(5));
        info(myResult1.getString(6));
        info(myResult1.getString(7));
    }
}

Fact Box visiblity in Form Ax 2012 X++

//Fact Box visiblity in Form Ax 2012 X++
PartList       partListFactBox  = new PartList(element);
 FormRun     formRunFactBox;
 int                i;
 for (i = 1; i <= partListFactBox.partCount(); i++)
 {
       formRunFactBox = partListFactBox.getPartById(i);
       formRunFactBox.design().visible(false);
 }

Upload data from Excel in D365FO X++

 Action Menu Item: SAN_UploadExcelData Object type: Class Object: <Controller class name> Label: <> Class: Controller class clas...