Wednesday, 2 April 2014

Export and Import Favorites

Index :
1. Export
2. Import
3. Copy

1. Export :

 void clicked()
{
    #AOT
    #TreeNodeSysNodeType
    #Properties
    #AviFiles
    CommaIo     fileOut;
    FileName    fileName;
    TreeNode menuTypeNode,parentnode,groupnode;
    str errmsg="";
    Dialog      dialog;
    DialogField fieldfilename;

    // Function which parses the treenode to get all its child nodes..
    void searchchildnode(TreeNode rootnode)
    {
        TreeNode childnode;
        TreeNodeIterator rootiterator = null;
        str object='Group',objecttype='Group',Label;
        String255 nodeType = 'Group';
        Label = groupnode.treeNodeName();
        if(rootnode)
        {
            //To send Group information to file
            fileOut.write(groupnode.treeNodeName(),rootnode.treeNodePath(),nodeType,Label,objecttype,object,rootnode.treeNodePath());
            rootiterator = rootnode.AOTiterator();
            childnode = rootiterator.next();
            while(childnode)
            {
                // Checks whether treenode is menuitem or folder
                //IF Menu Item then assign values required for creating as Favourite
                if (childnode.treeNodeType().id() == #NT_MENUITEM)
                {
                    nodeType = 'MenuItem';
                    objecttype = findProperty(childnode.AOTgetProperties(),#PropertyMenuItemType);
                    object = findProperty(childnode.AOTgetProperties(),#PropertyMenuItemName);
                    label = findProperty(childnode.AOTgetProperties(),#PropertyMenuItemLabel);
                    if(objecttype == 'Display')
                    {
                        menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Display\\' + object);
                        Label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                    }
                    else if(objecttype == 'Action')
                    {
                        menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Action\\' + object);
                        Label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                    }
                    else if(objecttype == 'Output')
                    {
                        menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Output\\' + object);
                        Label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                    }
                }
                //IF folder then assign values required for folder
                else
                {
                    nodeType = 'Folder';
                    Label = childnode.treeNodeName();
                    objecttype = 'Folder';
                    Object = 'Folder';
                }
                parentnode = childnode.AOTparent();
                // To pass the Group Name, Node path,Type of Node - folder/menuitem, Object Label, Object Type-display/output/Action, Object assigned for menu
                fileOut.write(groupnode.treeNodeName(),parentnode.treeNodePath(),nodeType,Label,objecttype,object,childnode.treeNodePath());
                // If have child nodes then perform Recursive action till End
                if(childnode.AOTchildNodeCount()>0)
                searchchildnode(childnode);
                childnode = rootiterator.next();
            }
        }
    }
    //Function to Parse through all the Favourite Groups.
    void getUserMenus()
    {
        TreeNode treeNode;
        TreeNodeIterator iterator;
        ;
        treeNode = infolog.userNode();
        iterator = treeNode.AOTiterator();
        treeNode = iterator.next();
        if (treeNode)
        {
            iterator = treeNode.AOTiterator();
            treeNode = iterator.next();
            // loop which parses all the Groups of favourites
            while (treeNode)
            {
                groupnode = treeNode;
                searchchildnode(treenode);
                treeNode = treeNode.AOTnextSibling();
            }
        }
    }
    #File
    dialog = new Dialog("Export");
    dialog.addText("Select your favorite customer:");
    fieldfilename= dialog.addField(extendedTypeStr(FilenameSave));
    dialog.filenameLookupFilter(["CSV","*.csv"]);
    dialog.filenameLookupTitle("Create Only CSV");
    dialog.run();
    if (dialog.closedOk())
    {
    fileName=fieldfilename.value();
    }
    fileOut = new CommaIo(filename, #io_write);
    if(fileOut)
    {
    getUserMenus(); // To parse all Favourite Groups
    }
    info("Favorites are imported to "+fileName);
}


2. Import :

void clicked()
{
    #File
    #TreeNodeSysNodeType
    #Properties
    #AOT
    #AviFiles
    IO  iO;
    TreeNode treenode,groupnode,checknode,menuTypeNode;
    MenuFunction mf;
    TreeNodeIterator iterator;
    FilenameOpen        filename;
    Container           record;
    boolean first = true;
    Menu menuNode;
    TreeNodePath path,objectpath;
    MenuItemType menutype;
    str object="",label="",objecttype="",nodeType,groupName,objectform;
    UserMenuList userMenu;
    boolean nodeexists;
    Dialog      dialog;
    DialogField fieldfilename;
    // Function to get the treenode in with Specified path.
        TreeNode searchchildnode(TreeNode rootnode,TreeNodeIterator tmpiterator,TreeNodePath xpath)
        {
            TreeNode childnode;
            TreeNodeIterator rootiterator = tmpiterator;
            TreeNodePath ypath;
            if(rootnode)
            {
                rootiterator = rootnode.AOTiterator();
                childnode = rootiterator.next();
                while(childnode)
                {
                    ypath = childnode.treeNodePath();
                    if(xpath == ypath)
                    {
                        treenode = childnode;
                        break;
                    }
                    if(childnode.AOTchildNodeCount()>0)
                        searchchildnode(childnode,rootiterator,xpath);
                    childnode = rootiterator.next();
                }
            }
            if(treenode == rootnode)
                return rootnode; // Sent Group node
            else
                return treenode; // send Exact path of where to add node.
        }
    ;
    // Open the dialog to select the file
    dialog = new Dialog("Import");
    dialog.addText("Select your favorite customer:");
    fieldfilename= dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(["CSV","*.csv"]);
    dialog.filenameLookupTitle("Upload only CSV");
    dialog.run();
    if (dialog.closedOk())
    {
        fileName=fieldfilename.value();
    }
    iO = new CommaTextIo(filename,#IO_Read);
    if (! iO || iO.status() != IO_Status::Ok)
    {
        throw error("File Cannot be Opened");
    }
    //Loops Until File End
    while (iO.status() == IO_Status::Ok)
    {
        record = iO.read();
        if (record)
        {
            nodeexists = true;
            groupName = conpeek(record, 1);
            path = conpeek(record, 2);
            nodeType  = conPeek (record,3);
            label = conpeek(record, 4);
            objecttype = conpeek(record, 5);
            object  = conPeek (record,6);
            objectpath =conPeek(record,7);
            treeNode = infolog.userNode();
            iterator = treeNode.AOTiterator();
            treeNode = iterator.next();
            groupnode = treeNode.AOTfindChild(groupName);
            //If specified Group is not created, it creates the Group.
            if(!groupnode)
            {
                userMenu = treeNode;
                userMenu.createMenu(groupName);
                treeNode = userMenu.AOTfindChild(groupName);
                menuNode = treeNode;
                menuNode.AOTsave();
            }
            if(nodeType != 'Group')
            {
            nodeexists = true;
            if(nodeType == 'MenuItem')
            {
                if(objecttype == 'Display')
                {
                    menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Display\\' + object);
                    label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                }
                else if(objecttype == 'Action')
                {
                    menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Action\\' + object);
                    label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                }
                else if(objecttype == 'Output')
                {
                    menuTypeNode = TreeNode::findNode(#MenuItemsPath +'\\Output\\' + object);
                    label = findProperty(menuTypeNode.AOTgetProperties(), #PropertyLabel);
                }
                if(!menuTypeNode)
                {
                nodeexists = false;  // If menu item doesn't exist in imported environment
                }
            }
            if(nodeexists)
                treeNode = searchchildnode(treeNode,iterator,path); // Get Node in specified path
            if(treeNode)
                checknode = treenode.AOTfirstChild();
            // Check whether the object is already existed in particular path
            while(checknode)
            {
                if(checknode.treeNodePath() == objectpath)
                {
                    nodeexists = false;
                    break;
                }
                checknode = checknode.AOTnextSibling();
            }
            // Condition to check If we get path and object do not exists then It creates new one.
            if (treeNode && nodeexists)
            {
                // To create folder to the Favourite...
                if(nodeType == 'Folder')
                {
                menuNode = treenode;
                menuNode.addSubmenu(label);
                menuNode.aotsave();
                //menuNode.save();
                }
                // To create Menu item
                if(nodeType == 'MenuItem')
                {
                    if(objecttype == 'Display')
                    {
                        menutype = MenuItemType::Display;
                        objectform = 'Form';
                    }
                    else if(objecttype == 'Action')
                    {
                        menutype = MenuItemType::Action;
                        objectform = 'Class';
                    }
                    else if(objecttype == 'Output')
                    {
                        menutype = MenuItemType::Output;
                        objectform = 'SSRSReport';
                    }
                    menuNode = treeNode;
                    mf = new MenuFunction(object,menutype);
                    mf.AOTsetProperty('Label',label);
                    mf.AOTsetProperty('ObjectType',objectform);
                    mf.AOTsetProperty('Object',object);
                    mf.AOTsave();
                    menuNode.addMenuitem(mf);
                    menuNode.AOTsave();
                    //menuNode.save();
                    }
                }
            }
        }
    }
info("Favourites Imported from" +fileName);
}

3. Copy Favorites Between Users :

 

Thursday, 20 March 2014

In Memory - SSRS reports

ProdCalcTransVarianceDP
===================

Once values are inserted to table, i need to modify and then update to table.

Since in report the temp table is 'Inmemory ' , the ProdCalcTransVarianceDP is applied to only one selected Prodid.

But my requirement is to get all ProdId's if prodid is not selected.
Modified , to  my requirment

/// <summary>
///    The <c>CitProdCalcTransVarianceSumryDP</c> class is the Report Data Provider class for the
///    <c>CitProdCalcTransVarianceSumry</c> report.
/// </summary>
/// REM 3/12/14 - CIT_245_VarianceSummaryReport
[SRSReportParameterAttribute(classStr(CitProdCalcTransVarianceSumryContract)),
 SRSReportQueryAttribute(queryStr(CitProdTableProdCalcTrans))]
class CitProdCalcTransVarianceSumryDP extends SRSReportDataProviderBase
{
    TmpProdStandardVariance         tmpProdStandardVariance;
    TmpProdStandardVariance         tmpProdStandardVarianceAll;
    ProdStandardVariance            prodStandardVariance;
}
private InventItemPrice getItemPrice(ProdTable prodTable)
{
    InventItemPrice inventItemPrice;
    InventCostTrans inventCostTrans;

    select firstonly TableId from inventCostTrans
        where inventCostTrans.InventTransId     == prodTable.InventTransId
            && inventCostTrans.CostTransType     == InventCostTransType::Receipt
            && inventCostTrans.CostTransState    == InventCostTransState::Financial
            && inventCostTrans.CostTransRefType  == InventCostTransRefType::Production
    join inventItemPrice
        where inventItemPrice.RecId == inventCostTrans.ItemPriceRefRecId;

    return inventItemPrice;
}

/// <summary>
/// Retrieves data from the <c>TmpProdStandardVariance</c> table.
/// </summary>
/// <returns>
/// Data from the <c>TmpProdStandardVariance</c> table.
/// </returns>
[SRSReportDataSetAttribute(tableStr(TmpProdStandardVariance))]
public TmpProdStandardVariance getTmpProdStandardVariance()
{
    select tmpProdStandardVarianceAll
        order by CalcType asc, CostGroupId asc
        where tmpProdStandardVarianceAll.InventCostLevel <= InventCostLevel::Single;

    return tmpProdStandardVarianceAll;
}

         private CostAmount getTotalVariance()
{
    TmpProdStandardVariance totalStandardVariance;

    totalStandardVariance.setTmpData(tmpProdStandardVarianceAll);
    select firstonly totalStandardVariance
        where totalStandardVariance.CalcType == ItemCalcType::Production;

    return totalStandardVariance.totalVariance();
}

         public void new(ProdStandardVariance _prodStandardVariance = ProdStandardVariance::construct(ProdTransRefType::Production))
{
    super();
    prodStandardVariance = _prodStandardVariance;
}

/// <summary>
/// Fetches the required data for the report.
/// </summary>
[SysEntryPointAttribute]
public void processReport()
{

    InventItemPrice         inventItemPrice;

    CitProdCalcTransVarianceSumryContract contract = this.parmDataContract() as CitProdCalcTransVarianceSumryContract;
    ProdTable               prodTable;
    CostAmount              totalVariance;
    //REM ->
    Query                   query = this.parmQuery();
    QueryRun                queryRun;
    ProdCalcTrans           prodCalcTransLoc;
    RecId                   recidCount = 1;
    //REM <-
    ;

    prodStandardVariance.citSetCalledFromVarianceSummaryReport(true); //REM
    queryRun = new QueryRun(query); //REM

    while (queryRun.next()) //REM
    {
        prodTable = queryRun.get(TableNum(prodTable));
        prodCalcTransLoc = queryRun.get(TableNum(prodCalcTrans));

        InventItemPrice = this.getItemPrice(prodTable);
        prodStandardVariance.calc(prodTable.ProdId,
                                  ProdTransRefType::Production,
                                  prodTable.CollectRefLevel,
                                  prodTable.CollectRefProdId,
                                  prodTable.RealDate);

        tmpProdStandardVariance.setTmpData(prodStandardVariance.parmTmpProdStandardVariance()); //Retrieve record set from class
        totalVariance = this.getTotalVariance();

        while select tmpProdStandardVariance
        {
            tmpProdStandardVariance.CitProdId = prodTable.ProdId;
            tmpProdStandardVariance.CitItemId = prodTable.ItemId;
            tmpProdStandardVariance.CitItemName = prodTable.itemName();
            tmpProdStandardVariance.CitDateEnded = prodCalcTransLoc.TransDate; //Date ended on 'Production' type record

            if (inventItemPrice.PriceCalcId)
            {
                tmpProdStandardVariance.LotSize = BOMCalcTable::find(inventItemPrice.PriceCalcId).Qty;
            }
            else
            {
                tmpProdStandardVariance.LotSize = inventItemPrice.PriceUnit;
            }
            tmpProdStandardVariance.TotalVarianceValue = totalVariance;
            tmpProdStandardVariance.ReportedGood = prodTable.reportedFinishedGood();
            tmpProdStandardVariance.update();

            //Insert all records in buffer into temp table used by report ->
            tmpProdStandardVarianceAll.data(tmpProdStandardVariance);
            tmpProdStandardVarianceAll.RecId = recidCount;
            recidCount ++;

            tmpProdStandardVarianceAll.insert();
            //Insert all records in buffer into temp table used by report <-
        }
    }
}

Wednesday, 12 March 2014

AIF

outbound services - triggered by AX or run by user, by batch process. Ex : whenever user posts picking list then i need to

send the xml.

Inbound - based on request AIF responds to it

Response - outbound * asynchronous
request and response - in adn outbound

Tools>> Application integration >> AIFDocumentService >> AIFCreate Document Service.

Rc on service >> Addins >> register service.
DO CIL
Then go to System Administraion >> setup >> service administraion integreation framework >> Inbound

NetTcp ( Adapter)

Service operations  ( add all the services methods to left pannel, Data policies ( enable all)

search - VS coomand  -
wcftestclient  >> enter

RC Add service >> , Paste teh WCF service operation.

Click any methods.

Select - find - Leave Call context - null
        Query criteria- Querycriteria
        Criteria Element - lenght -1
        DataSource name  - custtable
Fieldname , Operator - equal, value1 - give some value.

Create - Sender iD - USMF ( Company name)
    Class - entity... Mandatory while creating ( else throw error)


Check - Start new proxy Check  >> Click Invoke.

Monday, 10 March 2014

how to enable or disable security policy through code.

http://daxdilip.blogspot.in/2013/03/issue-with-security-policy-in-dynamics.html

 have found a workaround, by taking a different approach to the scenario and instead of attaching the Security Policy to the Role directly, I changed the ContextType to “ContextString” from the previously defined “Rolename” and put a ContextString called “DNTestSec”.
(Step 1)


I then attached this ContextString to the role and query. (Please see below Step 2 and Step 3)

After making this changes, the below code makes sense, as it can enable/disable security at run-time because it can find the ContextSecurity string. (Below is a standard ax code which you can find in one of the DirParty* forms in AOT)


{
    #DirParty
    XDSServices xds = new XDSServices();

 // Trigger the Dirparty table XDS  policies by passing the context string 
   xds.setXDSContext(0, #RestrictParty);
  super();

 // Disable the Dirparty XDS policy by passing a blank context string .

   xds.setXDSContext(0, ' ');
}

Sunday, 2 March 2014

Jobs on security

static void SecurityByRole(Args _args)
{

    SecurityRole securityRole;

    SecurityUserRole UserRole;

    SysUserInfo  userInfo;

    OMUserRoleOrganization roleOrganization;

    OMInternalOrganization internalOrganization;

    while select ID from userInfo

        order by id asc

        outer join UserRole

        where UserRole.User == userInfo.Id

            outer join securityRole

            where securityRole.RecId == UserRole.SecurityRole

            outer join roleOrganization

            where roleOrganization.User == userInfo.Id

            && roleOrganization.SecurityRole == UserRole.SecurityRole

                outer join internalOrganization

                    where internalOrganization.RecId == roleOrganization.OMInternalOrganization

        {

            print userInfo.Id, userInfo.Email, SysLabel::labelId2String(securityRole.Name), internalOrganization.Name ? internalOrganization.Name : "All Company";

           // pause;

    }

pause;

}

Thursday, 13 February 2014

jobs

1. How to copy object data to other object :
static void Job15(Args _args)
{
    Table2 a,b;
    a.CustAccount = "2014";
    a.Description = "hi";
    b =a;
    b.Description = "hello";
    info(strFmt("%1,%2",b.CustAccount,b.Description));

}
=====================================================================
static void jobjoinwherorderby(Args _args)
{
    InventSum inventsum;
    InventDim inventdim;
    InventLocation inventlocation;
    InventBatch inventbatch;
    int tot;
    while select * from inventsum
        join * from inventdim where inventsum.InventDimId == inventdim.inventDimId          
            join * from inventlocation where inventlocation.InventLocationId == inventdim.InventLocationId
                && inventlocation.InventLocationType == InventLocationType::Standard
                    join * from  inventbatch order by prodDate desc where inventdim.inventBatchId == inventbatch.inventBatchId                      
                 
    {
        tot++;
       
        //info(strFmt("%1,%2%3",inventsum.ItemId,inventsum.InventDimId,inventsum.PhysicalInvent));
    }
 info(strFmt("%1",tot));
}

Thursday, 6 February 2014

How to get balance in a year for a customer

static void PreviousYearBalance(Args _args)
{
int nowyear;
    transdate fromdate;
    transdate  enddate;
    CustTrans custtransloc;

    nowyear = year(today())-1;

    fromdate = str2DateDMY(strFmt("1/1/%1", nowyear));
    enddate = today();

    select sum (AmountMST) from custtransloc

        where custtransloc.AccountNum == "2014" &&
              custtransloc.TransDate       >= fromdate        &&
              custtransloc.TransDate       <= enddate ;

    info(strFmt("%1",custtransloc.AmountMST));
    //info(strFmt("%1",todate));
}