Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Error:- not able to retrieve after create in plugin

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am executing a plugin synchronously postOperation. I create an entity using IOrganizationService.create. This works, I get a GUID and I can see that the record exists in the CRM. Right after this, I am trying to retrieve the same record using same IOrganizationService and the GUID returned by the create call:

public void Execute(IServiceProvider serviceProvider)
    {
        ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
        IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
        tracer.Trace("context is " + context.InputParameters["Target"]);
        context.OutputParameters["Message"] = "in plugin";

        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
        {
/* some other processing here
.
.
*/
 Guid polId = service.Create(policy);
               Entity polEntity = service.Retrieve("new_customEntiry", polId, new ColumnSet(true));
 

But the polEntity.Id is null. polEntity["someattribute"] is also null .

Why is the retrieve call not working? What am I missing?

Thanks in advance!



Original post: stackoverflow.com/.../error-not-able-to-retrieve-after-create-in-plugin

 
  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Error:- not able to retrieve after create in plugin

    This is depends on time taken  to create the record , when plugin executes in  synchronous mode means that  service will execute unknowingly whether your create operation succeeded or not. So there is no guarante that each retrieve operation/service  will return data in case of synchronous plugin.

    But in case of asynchronous plugin the retrieve operation will wait until create operation succeeded due to dependency execution order.

    For better understanding you may refer below reference-

    docs.microsoft.com/.../dependency-execution-order-asynchronous-operations

    docs.microsoft.com/.../asynchronous-service-architecture

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error:- not able to retrieve after create in plugin

    Thanks a Gautam!

    Changing it to async worked.

    I am interested in knowing what's the difference between the two in the sense that why won't the synchronous call work if its using the same service? I am able to retrieve other entities after the create call.

  • Verified answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Error:- not able to retrieve after create in plugin

    When you are creating record inside plugins that means you have all details of the created record in the plugin itself , so thete os no need to retrieve again.

    If you still want to retrieve then try to change plugin run with asynchronous mode.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans