web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

SysExcelApplication.construct running in CIL on the client.

(0) ShareShare
ReportReport
Posted on by 632

Dear Friends,

I have a batch job regarding import movement journal excel file, the class itself works fine, but if I run a batch job using this class I getting the error:

SysExcelApplication.construct running in CIL on the client.

46757.Capture.PNG

Please tell me how to solve this error.

Thanks & Regards,

Rahul

I have the same question (0)
  • WillWU Profile Picture
    22,363 on at

    Hi Rahul.p,

    It says that you're using SysExcelApplication(client) method there, which can't work, because CIL exist only on server and batch server doesn't have any client at all.

    You can't use SysExcelApplication from a batch job that executes on the server because Excel is a client application.

    Please have a look at the following blog.

    https://stackoverflow.com/questions/13948769/using-winapiserver-and-sysexcelapplication-class-in-batch-job

    Hope this helps.

  • WillWU Profile Picture
    22,363 on at

    Hi partner,

    You can use Data Import Export Framework in AX.

    It supports both Excel files and batch processing.

  • Rahul.p Profile Picture
    632 on at

    It means we can not do import movement journal using batch job by Batch Processing?

    And is there any way to import movement journal using code by Batch Processing?

  • WillWU Profile Picture
    22,363 on at

    Hi partner,

    Yes.

    You can convert Excel to CSV file.

    Then you can use the TextIO class to import CSV file after moving it to the folder for AX to import as CSV file.

  • Rahul.p Profile Picture
    632 on at

    how to convert Excel to CSV file.

    I change file format CSV but while try to import only Excel file is coming CSV file is not coming.

  • WillWU Profile Picture
    22,363 on at

    Hi partner,

    Please refer to the following code to read the csv file.

        CommaTextIo       commaTextIo;      
        fileiopermission     permission;
        container              c;
        int                        x;
        int                        cols;
    
        permission = new fileiopermission('c:\\test.csv',#io_read);
        permission.assert();
    
        // specify the source file name ie. "test.csv"
        commaTextIo = new CommaTextIo('c:\\test.csv','r');
        c = commaTextIo.read();
    
        while(c)
        {
            cols = conlen(c);
            for(x = 1; x <= cols; x  )
            {
                  info (any2str(conpeek(c,x)));
            }
            c = commaTextIo.read();
       }
    
       commaTextIo = null;

  • Rahul.p Profile Picture
    632 on at

    I changed the format Excel to CSV but still i am getting same error.

  • WillWU Profile Picture
    22,363 on at

    Hi,

    Have you used the SysExcelApplication class.

    Please provide your code if possible.

  • Rahul.p Profile Picture
    632 on at

    Yes i used SysExcelApplication.

    ImportMovementJournal()

    private void importMovementJournal()
    {
        ABC_MovementJournalTmp              movementJournal;
        InventJournalTrans                  inventJournalTrans;
        InventJournalTable                  inventJournalTable;
        InventDim                           inventDim;
        Voucher                             voucherNum;
        boolean                             insertSuccess = false;
        int                                 noOfLines = 0;
        InventItemPrice                     inventItemPrice;
        ABC_MovementJournalAccountRelation  movementJournalAccountRelation;
    
        
        InventJournalTable_IN               inventJournalTable_IN;
        InventJournalTrans_IN               inventJournalTrans_IN;
        InventJournalTransTaxExtensionIN    inventJournalTransTaxExtensionIN;
        TaxInformation_IN                   taxInformation_IN;
        LogisticsPostalAddress              logisticsPostalAddress;
        LogisticsLocation                   logisticsLocation;
        int                                 linenum;
       
    
        inventJournalTable.clear();
    
        inventJournalTable.initFromInventJournalName(inventJournalName);
    
        inventJournalTable.JournalId = NumberSeq::newGetNum(LedgerParameters::numRefJournalNum()).num();
    
        if (inventJournalTable.validateWrite())
        {
            inventJournalTable.insert();
    
            
    
           
            inventJournalTable_IN.InventJournalTable = inventJournalTable::find(inventJournalTable.JournalId).RecId;
    
           
            inventJournalTable_IN.validateWrite();
            inventJournalTable_IN.insert();
    
           
    
            while select movementJournal
            {
                select firstOnly inventDim
                    where inventDim.InventLocationId    == movementJournal.InventLocationId
                        && inventDim.InventSiteId       == movementJournal.InventSiteId;
                if (!inventDim)
                {
    
                    inventDim.initFromInventTable(InventTable::find(movementJournal.ItemId));
    
                    inventDim.InventLocationId  = movementJournal.InventLocationId;
                    inventDim.InventSiteId      = movementJournal.InventSiteId;
                    inventDim.inventDimId       = inventDim::newDimId();
                    inventDim.insert();
                }
    
                inventJournalTrans.clear();
                inventJournalTrans.initValue();
                inventJournalTrans.initFromInventJournalTable(inventJournalTable);
    
                inventJournalTrans.JournalId                = inventJournalTable.JournalId;
    
                voucherNum = new JournalVoucherNum(JournalTableData::newTable(inventJournalTable)).getNew(false);
    
                inventJournalTrans.Voucher                  = voucherNum;
                inventJournalTrans.TransDate                = movementJournal.TransDate;
                inventJournalTrans.WarehouseLocation_IN     = inventJournalTrans.nttGetLogisticsLocation_IN(movementJournal.InventLocationId).RecId;
                inventJournalTrans.PostalAddress_IN         = LogisticsPostalAddress::findByLocation(inventJournalTrans.WarehouseLocation_IN).RecId;
                inventJournalTrans.ItemId                   = movementJournal.ItemId;
                inventJournalTrans.DefaultDimension         = InventTable::find(movementJournal.ItemId).DefaultDimension;
                inventJournalTrans.Qty                      = movementJournal.Qty;
                inventJournalTrans.InventDimId              = inventDim.inventDimId;
                inventJournalTrans.ExciseType_IN            = ExciseType_IN::Manufacturer;
                inventjournalTrans.ABC_Remarks              = movementJournal.ABC_Remarks;  // MovementJournal_Remarks
                itemGroup                                   = InventItemGroupItem::itemGroupByItemIdLegalEntity(movementJournal.ItemId,curext()).ItemGroupId;
    
                if (inventJournalName.NTTConsumptionJournal == NoYes::Yes)
                {
                   select firstOnly movementJournalAccountRelation where movementJournalAccountRelation.ItemGroupId  == itemGroup
                                                                     &&  movementJournalAccountRelation.MovementType == ABC_MovementType::Consumption;
                    if (movementJournalAccountRelation)
                    {
                        inventJournalTrans.LedgerDimension  = movementJournalAccountRelation.OffSetAccount;
                    }
                }
                else if (inventJournalName.NTTConsumptionJournal == NoYes::No)
                {
                    select firstOnly movementJournalAccountRelation where movementJournalAccountRelation.ItemGroupId  == itemGroup
                                                                      &&  movementJournalAccountRelation.MovementType == ABC_MovementType::Produce;
                    if (movementJournalAccountRelation)
                    {
                        inventJournalTrans.LedgerDimension  = movementJournalAccountRelation.OffSetAccount;
                    }
                }
    
                if (inventJournalTrans.Qty >=0 )
                {
                    select firstOnly inventItemPrice
                        order by ActivationDate desc
                        where inventItemPrice.ItemId == inventJournalTrans.ItemId;
    
                    if (inventItemPrice)
                    {
                        inventJournalTrans.CostPrice        = inventItemPrice.Price;
                        inventJournalTrans.CostAmount       = round((inventItemPrice.Price * inventJournalTrans.Qty),0.01);
                    }
                }
    
                if (inventJournalTrans.validateWrite())
                {
                    inventJournalTrans.insert();
    
                   
                    linenum  ;
                    //Get Invent journal trans info for India
                    select InventJournalTrans
                     where inventJournalTrans.ItemId    == movementJournal.ItemId
                       &&  InventJournalTrans.JournalId == inventJournalTable.JournalId
                       &&  inventJournalTrans.LineNum   == linenum;
    
                    inventJournalTrans_IN.InventJournalTrans = InventJournalTrans.RecId;
    
                    //Insert Invent journal trans info for India
                    inventJournalTrans_IN.validateWrite();
                    inventJournalTrans_IN.insert();
    
                    //Relate Invent journal trans info to Tax info for India
                    inventJournalTransTaxExtensionIN.InventJournalTrans = InventJournalTrans.RecId;
    
                    //Get Tax info for India
                    select logisticsLocation
                     where LogisticsPostalAddress::getLocation(inventJournalTrans.PostalAddress_IN) ==  logisticsLocation.RecId;
    
                    inventJournalTransTaxExtensionIN.TaxInformation_IN
                    = taxInformation_IN::findDefaultbyLocation(logisticsLocation.RecId).RecId;
    
                    //Insert Tax info for India
                    inventJournalTransTaxExtensionIN.validateWrite();
                    inventJournalTransTaxExtensionIN.insert();
    
                  
    
                    noOfLines  ;
                    this.setTaxExciseInfo(inventJournalTrans, inventJournalTrans.PostalAddress_IN);
    
                    insertSuccess = true;
                }
            }
            this.updateInventJournalTab(inventJournalTable, noOfLines);
        }
    
        if (insertSuccess == true)
        {
    
             
            info("Moment Journal Import successfully");
            
    
        }
    }

    readImportFile()

    public void readImportFile()
    {
        #AviFiles
    
        str COMVariant2Str(COMVariant       _cv,
                           int _decimals    = 1,
                           int _characters  = 0,
                           int _separator1  = 0,
                           int _separator2  = 0)
        {
            switch(_cv.variantType())
            {
                case COMVariantType::VT_BSTR:
                    return _cv.bStr();
    
                case COMVariantType::VT_R4:
                    return num2str(_cv.float(),
                                    _characters,
                                    _decimals,
                                    _separator1,
                                    _separator2);
    
                case COMVariantType::VT_R8:
                    return num2str(_cv.double(),
                                    _characters,
                                    _decimals,
                                    _separator1,
                                    _separator2);
    
                case COMVariantType::VT_DECIMAL:
                    return num2str(_cv.decimal(),
                                    _characters,
                                    _decimals,
                                    _separator1,
                                    _separator2);
    
                case COMVariantType::VT_DATE:
                    return date2str(_cv.date(), 123, 2, 1, 2, 1, 4, DateFlags::None);
    
                case COMVariantType::VT_EMPTY:
                    return "";
    
                default:
                    throw error(strfmt("@SYS26908",
                                        _cv.variantType()));
            }
    
            return "";
        }
        ;
        row = 1;
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        try
        {
            workbooks.open(filename);
        }
    
        catch (Exception::Error)
        {
            throw error("@SYS19358");
        }
    
        workbook    = workbooks.item(1);
        worksheets  = workbook.worksheets();
        worksheet   = worksheets.itemFromNum(1);
        cells       = worksheet.cells();
    
        ttsBegin;
        do
        {
            try
            {
                row  ;
                this.insertMovementTmp(str2Date(COMVariant2Str(cells.item(row,1).value()), 123),        //Transdate
                                        COMVariant2Str(cells.item(row,2).value()),                      //ItemId
                                        COMVariant2Str(cells.item(row,3).value()),                      //Site
                                        COMVariant2Str(cells.item(row,4).value()),                      //Warehouse                              
                                        str2num( COMVariant2Str( cells.item(row,5).value(), 2 ) ),      //Qty                                
                                        COMVariant2Str(cells.item(row,6).value()));                     //Remarks
    
            }
            catch
            {
                Error(strfmt("@SYS92842"));
            }
    
            type = cells.item(row   1, 1).value().variantType();
    
        } while (type!= COMVariantType::VT_EMPTY);
    
        ttscommit;
        application.quit();
    }

  • Verified answer
    WillWU Profile Picture
    22,363 on at

    Hi friend,

    I mentioned above.

    The SysExcel classes are pegged on the client, which means they won't work in batch as they are.

    You can use the TextIO class to import CSV in batch.

    XLS file can't be imported in batch because you need to use the SysExcel classes which don't work in batch.

    You need to convert it to CSV file manually and do not use the sysexcel class again.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans