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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to import excel file by entity via x++

(0) ShareShare
ReportReport
Posted on by 1,965

Hi,

want to create a form with upload button, this upload button should take excel files only. Once uploaded and then when I click ok,  it should take the values and import them to an already existing data project that supports excel and has an entity in it.

What code should I write?

I have the same question (0)
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Here comes my question. Instead of using the some entity the standard functionality, why is it required to divert that by adding a new form with upload button and again going to entity. Instead you can directly go to entity and create an import project and do the import right?

  • .. Profile Picture
    1,965 on at

    Hi Baharani,

    I want to do it like that because I want to import vendor catalog and this is how vendor catalog works. But the thing is that vendor catalog only supports xml and I want to it to support excel.

    So in general how can I import the uploaded excel file to an existing data project by code?

  • Suggested answer
    Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    Yes, it can be done.

    You can utilize DMFQuickImportExport::doPGImport(). If you put it to a search engine, you'll fine several examples. Some may also exist in the standard application (you can try "Find references" on doPGImport().

  • .. Profile Picture
    1,965 on at

    Hi Martin,

    I'm trying to do similar to what a standard method is doing, but the difference is that the standard one is XML and it's calling these two methods in Order.

    Now since i want Excel,

    For the first method “preProcessCatalogMaintenanceRequestXML”  -- how can i change it to add uploadDateTime field to excel instead of XML?

    For the 2nd method “importCatalogFile” – I think I should leave it as is, except for replacing composite entity (DictCompositeDataEntity ) class and get single entity instead, correct?

    protected void preProcessCatalogMaintenanceRequestXML()
        {
            CatVendorDateTime uploadDateTime = CatVendorCatalogMaintenanceRequest::findRecId(catVendorCatalogMaintenanceRecId).UploadDateTime;
    
            XmlDocument xmlDoc = XMLDocument::newFromStream(fileStream);
    
            XMLElement catalogMaintenanceRequestNode = xmlDoc.documentElement().getNamedElement(tableStr(CatVendorCatalogMaintenanceRequestEntity));
            XMLNode uploadDateTimeNode = xmlDoc.createElement(fieldStr(CatVendorCatalogMaintenanceRequestEntity, UploadDateTime));
           
            if (CatVendorCatalogImportUploadDateTimeFormatFlight::instance().isEnabled())
            {
                uploadDateTimeNode.text(DateTimeUtil::toStr(uploadDateTime));
            }
            else
            {
                uploadDateTimeNode.text(datetime2Str(uploadDateTime));
            }
    
            catalogMaintenanceRequestNode.appendChild(uploadDateTimeNode);
           
            System.IO.MemoryStream outputStream = new System.IO.MemoryStream();
            ClrObject inputArray = System.Text.Encoding::get_UTF8().GetBytes(xmlDoc.InnerXML());
            outputStream.Write(inputArray, 0, inputArray.get_length());
    
            fileId = this.uploadFileToTempStorage(outputStream, fullFileName);
        }
    


     private void importCatalogFile()
        {
            DMFDefinitionGroup  definitionGroup = CatVendorCatalogMaintenance::findVendorCatalogDefinitionGroup();
            DMFExecutionId      executionId     = DMFUtil::setupNewExecution(definitionGroup.DefinitionGroupName);
    
            ttsbegin;
            // Find execution
            DictCompositeDataEntity compositeDataEntity = new DictCompositeDataEntity(this.compositeDataEntityName());
            DMFDefinitionGroupExecution execution =
                        DMFDefinitionGroupExecution::find(definitionGroup.DefinitionGroupName, compositeDataEntity.label(), executionId, true);
            execution.IsTransformed = NoYes::No;
            execution.FilePath = execution.applyTransforms(fileId);
            execution.IsTransformed = NoYes::Yes;
            execution.update();
            ttscommit;
    
            // Import data. Wait for data to be imported
            DMFQuickImportExport::doPGImport(definitionGroup.DefinitionGroupName, executionId);
    
            infolog.clear();
        }
    

  • Martin Dráb Profile Picture
    237,722 Most Valuable Professional on at

    The question of modifying the Excel file don't belong to this thread (which is about "How to import excel file by entity via x++"). Feel free to create a new thread (with an appropriate title) and explain your requirements there.

    By the way, you're asking here for a long time - you should already know how to use Insert > Code.

    Regarding importCatalogFile(), you definitely need another entity name. Whether  doing such thing make sense in that (unknown) is not something I can evaluate.

  • .. Profile Picture
    1,965 on at

    Hi Martin,

    Sorry the rich formatting was stuck, i amended it.

    I created a new question for the other part, can you please help?

    community.dynamics.com/.../how-to-add-an-additional-excel-field-to-an-existing-excel-file

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 687 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 535 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 403 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans