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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

import entity through code

(0) ShareShare
ReportReport
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!

I have the same question (0)
  • Verified answer
    Pankaj Gogoi Profile Picture
    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
    14,065 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
    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
    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

Responsible AI policies

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

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 225

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 129 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans