Wednesday, October 28, 2015

AX R3 - Access Denied: MCRInventSearchController

The following is taken from http://www.axdeveloperconnection.it/webapp/ (BY LANE | MONDAY, JULY 14, 2014 ( 1 YEAR 3 MONTHS ) before it went down. All credit goes to the original creator.

During our validation phase of the AX R3 upgrade project, we found some issues regarding security for our product configuration department staff.  This is likely due to developing highly customized roles for our users, to keep licensing costs low.  Even so, we expected most new menu items to go in to existing privileges for the majority of users.  In any case, you may run in to this error message:

If you trace this, you'll want to start at the EcoResProductTranslation table, update method.  In there, you'll see a static call to MCRInventSearch::updateFromProduct().

You'll need to give access to the highlighted class and method as a ServerMethod on either a privilege, duty, or role so that users can change the product names.  Given, that the Trade Item Search configuration key is enabled.

E.g.

Tuesday, October 27, 2015

Programmatically change project group for each project

//as long as we have the proj id and the group to change, we can use the inbuilt classes to change it for us.

private static void changeGroupPerReord(projtable _currentRecord, ProjgroupID _toProjGroupID)
{
    ProjGroupChange projGroupChange;
    ProjTable       projTable;
    Common          currentRecord = _currentRecord;

    if (!currentRecord)
    {
        throw error(strFmt("@SYS29104", classId2Name(classIdGet(projGroupChange))));
    }

    projGroupChange = new ProjGroupChange();

    projGroupChange.getLast();
    projGroupChange.parmProjGroupIdTo("");
    projGroupChange.parmProjInvoiceProjId("");
    projGroupChange.parmProjGroupIdTo(_toProjGroupID);
    projTable       = currentRecord;
    if (ProjWIPTable::exist(projTable.ProjId))
    {
        projGroupChange.parmProjWIPId(projTable.ProjId);
        projGroupChange.parmProjType(projTable.Type);
        projGroupChange.parmProjGroupIdFrom(projTable.ProjGroupId);
        projGroupChange.parmShowChild(false);
        projGroupChange.parmProjId("");
    }
    else
    {
        projGroupChange.parmProjId(projTable.ProjId);
        projGroupChange.parmProjType(projTable.Type);
        projGroupChange.parmProjGroupIdFrom(projTable.ProjGroupId);
        projGroupChange.parmShowChild(true);
        projGroupChange.parmProjWIPId("");
    }


    projGroupChange.run();

}

Open a CSV through a dialog box and read it

 private static void openCSVAndReadIt(Args args)
{
    #File
    IO  iO;
    Dialog dialog;
    DialogField     dialogFilename;
    ProjId projId;
    ProjGroupId fromProjGrpId;
    ProjGroupId toProjGrpId;
    FilenameOpen        filename;
    Container           record;
    boolean first = true;
    ;
    dialog = new Dialog("ProjGrp Change");

    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(["@SYS100852","*.csv"]);

    dialog.caption("ProjGrp Change");
    dialogFilename.value(filename);
    if(!dialog.run())
        return;
    filename = dialogFilename.value();

    iO = new CommaTextIo(filename,#IO_Read);
    if (! iO || iO.status() != IO_Status::Ok)
    {
        throw error("@SYS19358");
    }
    while (iO.status() == IO_Status::Ok)
    {
        record = iO.read();// To read file
        if (record)
        {
            if (first)  //To skip header
            {
                first = false;
            }
            else
            {

                //do your logic here, in my case I will be using it change project groups as mentioned in the next blog post

                projId = conpeek(record, 1);//To peek record
                toProjGrpId = conpeek(record, 4);
                ProjGrpChangeCSV::changeGroupPerReord(ProjTable::find(projId),toProjGrpId);
            }
        }
    }
}

Monday, October 19, 2015

Another instance of CIL generation is already in progress

If AX crashes while doing a full CIL, a record is left behind that does not allow CIL again and gives the Another instance of CIL generation is already in progress.

You can delete the record from SysLastValueTable. It has UserID = '-AutoSem' and ElementName = 'Cil Generation'.