Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

import entity through code

Posted on by 7,316

Hi,

I am trying to import data from a csv file programmatically.

For that, I am using crmserviceclient to connect to my application and creating 'Import' entity like this:

CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyDynamicsWebJobCon"].ConnectionString);

                IOrganizationService service;
                service = (IOrganizationService)crmSvc.OrganizationWebProxyClient != null ? (IOrganizationService)crmSvc.OrganizationWebProxyClient : (IOrganizationService)crmSvc.OrganizationServiceProxy;
                OrganizationServiceContext orgContext = new OrganizationServiceContext(service);

                // Create the Import
                Entity import = new Entity("import");
                import.Attributes.Add("modecode", new OptionSetValue(0));
                import.Attributes.Add("name", "CustomEntityDataImport");
                import.Attributes.Add("sendnotification", false);
                import.Id = service.Create(import);
                Console.WriteLine(import.Id);
                Console.ReadLine();

Not sure why am I not seeing this created import record in my application. When I debug, I do see the guid of the created import record but I can't find it in the application.

I am working on Dynamics 365 Online. Can somebody please guide me in finding this missing record? I can't 'advanced find' it either.

Thanks for any help!

  • Verified answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: import entity through code

    Please use the entity imports

    ../api/data/v9.1/imports

    Best Regards

    PG

  • Verified answer
    David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: import entity through code

    To create a data import, you need to create an importfile record as well as an import record. The Imports section of the application is actually a list of importfile records that are linked to an import record.

    Note that I think you'll also need to set the isimport attribute on the import record that you create.

    For reference, the following fetchxml is the query used to display 'My Imports' in the application

    <fetch version="1.0" output-format="xml-platform" mapping="logical">

    <entity name="importfile">

    <attribute name="name" /><attribute name="statuscode" /><attribute name="createdon" /><attribute name="createdby" /><attribute name="importfileid" /><attribute name="successcount" /><attribute name="partialfailurecount" /><attribute name="failurecount" /><attribute name="totalcount" />

    <order attribute="createdon" descending="true" />

    <link-entity name="import" from="importid" to="importid" alias="isimport" visible="false"><filter type="and"><condition attribute="isimport" operator="eq" value="1" /></filter></link-entity>

    <filter type="and"><condition attribute="ownerid" operator="eq-userid" /><condition attribute="filetypecode" operator="neq" value="2" /></filter>

    </entity>

    </fetch>

  • meenoo Profile Picture
    meenoo 7,316 on at
    RE: import entity through code

    Thanks Pankaj.

    Yes, I have tested other code with the same connection string. It is working fine.

    I looked at web api query, i didn't find any record. What entity should I be querying for to get the newly created import record? I see only 3 import entities(importdataset, importfiles, importmaps).

  • Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: import entity through code

    Hello Meenoo,

    Verify if you are connecting to the Correct Dynamics 365 instance.

    Use the Web API query and see if you get the record.

    https://<<yourcrm>>/api/data/v9.0/entitynames(guid)

    Best Regards

    PG

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans