Monday, 15 December 2014

Upload Inventory reorder level through csv in AX 2012


public class ssUploadInventReorderLevel_VS extends RunBase
{
    CommaIO                     csvFile;
    Filename                    filename;
    container                   readCon;
    counter                     inserted;

    args                        args;
    DialogField                 dialogFilename;

    ReqItemTable                reqItemTableGlobal;

    #define.CurrentVersion(2)
    #localmacro.CurrentList
        filename,
        inserted,
    #endmacro

    #localmacro.ListVersion1
        filename,
        inserted
    #endmacro

    #File
}

public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialog.caption("Upload inventory reorder level");

    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));

    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);

    return dialog;
}


public boolean getFromDialog()
{
    filename = dialogFilename.value();

    return true;
}
void run()
{
    boolean                 first = true;
    ;

    csvFile = new CommaIO(filename, 'r');

    try
    {
        if (csvFile)
        {
            ttsbegin;

            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();

                if (readCon)
                {
                    reqItemTableGlobal.clear();

                    reqItemTableGlobal.CovFieldsActive          = NoYes::Yes;
                    reqItemTableGlobal.CovRule                  = ReqCovType::MinMax;
                    reqItemTableGlobal.CovPeriod                = 1;
                    reqItemTableGlobal.CovTimeFence             = 100;
                    reqItemTableGlobal.MaxNegativeDays          = 2;
                    reqItemTableGlobal.MaxPositiveDays          = 365;
                    reqItemTableGlobal.CalendarDaysTransfer     = NoYes::Yes;
                    reqItemTableGlobal.ReqGroupId               = "Group";
                    reqItemTableGlobal.CapacityTimeFence        = 100;
                    reqItemTableGlobal.ExplosionTimeFence       = 100;
                    reqItemTableGlobal.PmfPlanPriorityCurrent   = 99;
                    reqItemTableGlobal.PmfPlanPriorityDefault   = 99;
                    reqItemTableGlobal.MinSatisfy               = ReqMinSatisfy::TodaysDate;
                    reqItemTableGlobal.ReqPOType                = ReqPOType::Purch;

                    reqItemTableGlobal.CovInventDimId   = conPeek(readCon,1);
                    reqItemTableGlobal.ItemId           = conPeek(readCon,2);
                    reqItemTableGlobal.MaxInventOnhand  = conPeek(readCon,5);
                    reqItemTableGlobal.MinInventOnhand  = conPeek(readCon,6);

                    if(!ReqItemTable::find(reqItemTableGlobal.ItemId, reqItemTableGlobal.CovInventDimId) && reqItemTableGlobal.itemId)
                    {
                        reqItemTableGlobal.insert();
                        inserted++;
                        info(strFmt("%1 inserted",inserted));
                    }
                }
            }
            ttsCommit;
        }
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,inserted));
    }
}


static void main(Args  args)
{
    ssUploadInventReorderLevel_VS        uploadInventReorderLevel;
    ;

    uploadInventReorderLevel =  new ssUploadInventReorderLevel_VS();

    if (uploadInventReorderLevel.prompt())
    {
        uploadInventReorderLevel.run();
    }
}

No comments:

Post a Comment