Thursday, August 11, 2016

FA upload ax 2012

//FA upload ax 2012
static void UploadFAseetbook(Args _args)
{
    CommaTextIO           csvFile;
    container                   readCon;
    counter                     icount,inserted;
    Dialog                      dialog;
    DialogField              dfFileName;
    FileName                    fileName;
    int                         Ccount;
    Struct                      struct;
    DimensionDefault            DimensionDefault;
    AssetId         assetid;
    AssetBookId     bookid;
    Description     NAme;
    str usedfromdate;
    date useddate;
    AssetGroupid  AssetGroup;
    AssetBook   assetBook;
    container   ledgerDimension;
    int i;
    AssetTable      assetTable;
    DimensionDefault DefaultDimensionCreate(Description _BU,Description _CC,Description _Department)
    {
        DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault result;
        int j;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue; //DimensionAttributeValueCombination
        container conAttr = ["BusinessUnit","CostCenter","Department"]; //101,106,1
        container conValue;
        str dimValue;
        conValue = [_BU,_CC,_Department];
        dimValue = "";
        j = 0;
        for (j = 1; j <= conLen(conAttr); j++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,j));
            if (dimensionAttribute.RecId == 0)
            {
                continue;
                //control will not go down
            }
            dimValue = conPeek(conValue,j);
            if (dimValue != "")
            {
                dimensionAttributeValue =
                dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
        result = valueSetStorage.save();

        return result;
    }
    ;
    inserted =0;
    #File
   
   
    dialog = new Dialog("Pick the file");
    dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
    dialog.filenameLookupFilter(["All files", #AllFiles]);

    if (dialog.run())
    {
        csvFile = new CommaTextIo(dfFileName.value(), 'r');
        csvFile.inFieldDelimiter(',');
        readCon = csvFile.read();
       
        while(csvFile.status() == IO_Status::OK)
        {
            readCon = csvFile.read();
            if(readCon)
            {
                icount++;
                assetid = conPeek(readCon,2);
                NAme = conPeek(readCon,9);
                bookid = conPeek(readCon,3);
                AssetGroup = conPeek(readCon,1);
                usedfromdate = conPeek(readCon,12);
               
                assetTable.clear();
                assetTable.AssetId = assetid;
                assetTable.Name = NAme;
                assetTable.NameAlias = NAme;
                assetTable.AssetGroup = AssetGroup;
                assetTable.AssetType = AssetType::Tangible;
                assetTable.Quantity = 1;
                assetTable.Location = conPeek(readCon,16);
                assetTable.insert(); 
                i++;
               
                assetBook.clear();
                assetBook = AssetBook::find(assetid,bookid,true);
                ttsBegin;
                select forUpdate assetBook
                    where assetBook.AssetId == assetid;
                if(assetBook)
                {
                    assetBook.AssetGroup = AssetGroup;
                    assetBook.BookId = bookid;
                    assetBook.Status = AssetStatus::NoAcquisition;
               
                    DimensionDefault = DefaultDimensionCreate(conPeek(readCon,8),conPeek(readCon,15),conPeek(readCon,13));
                    assetBook.DefaultDimension = DimensionDefault;
               
                    assetBook.PostingProfile        = conPeek(readCon,10);
                    assetBook.Depreciation          = NoYes::Yes;
                    assetBook.LifeTime              = conPeek(readCon,14);
                    assetBook.AcquisitionPrice      = conPeek(readCon,5);
                    assetBook.AcquisitionDate       =  str2Date(conPeek(readCon,4),213);
                    assetBook.UsedFromDate          = str2Date(usedfromdate,213);
                    assetBook.ServiceLife           = conPeek(readCon,11);
                    assetBook.LifeTimeRest          = conPeek(readCon,7);
                    assetBook.update();
                }
                else   
                {
                    info(strFmt("Value Model not updated,%1,%2",assetid));
                }
                ttsCommit;
               
            }
        } 
        info(strFmt("No of Record updated %1",i));
    }
}
//
               

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...