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 CRM (Archived)

Post Create plugin step - record does not exist

(0) ShareShare
ReportReport
Posted on by 2,665

Hi,

I am trying to trigger a plugin on save of a record and use the newly created entity id to create a new lookup record(Document location). But I am seeing record Id does not exist error on this line:

iService.Create(spDocLoc);

Here is the snippet of my pluign:

 public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext iContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
           
            IOrganizationServiceFactory iServFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            IOrganizationService iService = iServFactory.CreateOrganizationService(iContext.UserId);

            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            if (iContext.InputParameters.Contains("Target") && iContext.InputParameters["Target"] is Entity && iContext.MessageName.ToLower() == "create")
            {
                Entity entAccount = (Entity)iContext.InputParameters["Target"];
                if (entAccount.LogicalName == "new_document")
                {
                    if (entAccount.Attributes.Contains("new_typeofdocument"))
                    {
                        EntityReference documenttypeId = (EntityReference)entAccount.Attributes["new_typeofdocument"];

                        Entity newdocumentType = new Entity("new_documenttype");
                        newdocumentType.Attributes = new AttributeCollection();

                        Entity documentTypeName = iService.Retrieve("new_documenttype", documenttypeId.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_documenttype"));
                        typeofDocument = documentTypeName.Attributes["new_documenttype"].ToString();
                      
                    }
                }
             
                string strURL = GetLocation(iService,typeofDocument,entAccount.Id);

            }
        }

 private static string GetLocation(IOrganizationService iService, string FolderName, Guid entAccountID)
        {
               Guid _spParentLocId = new Guid("3F381014-5723-E611-80DF-0050569C2FED");
           
            SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
            {
                Name = "Documents on Default Site 1",
                Description = null,
                
                RegardingObjectId = new EntityReference("new_document", entAccountID),

                ParentSiteOrLocation = new EntityReference(SharePointDocumentLocation.EntityLogicalName, _spParentLocId),
                RelativeUrl = FolderName
            };

            Guid _spDocLocId = iService.Create(spDocLoc);
            // Console.WriteLine("{0} created.", spDocLoc.Name);
            return _spDocLocId;

        }


I've registered plugin on create of document entity and post operation(synchronous).

The record id does not get created in the database unless this plugin executes successfully. Since its throwing error, the record does not get saved. But I need to use the id to create document location immediately after saving document entity. How do I get all this working? What am I missing? Please guide me through this.

Thank you.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Manuesev Profile Picture
    115 on at
    RE: Post Create plugin step - record does not exist

    The problem is that you are trying of debug a post operation plugin which is probably using EARLY BOUND.

    In order to find the real error of your assembly, switch your code to a Late bound one. Then, when everything was fixed, you can switch to an early bound accomplish again.

  • Community Member Profile Picture
    on at
    RE: Post Create plugin step - record does not exist

    I had the same issue. In my case I would create the a folder in sharepoint and after create subfolders, related with my entity record I just had created. I could not debug because I would get the same error, but if you are not debugging the plugin works normally. So my advise here is create a console application to do the exactly same thing, just for your tests, in this console app you can either create a new record or use an exist and make your tests and later when you publish your plugin it will work just fine if you are not debugging

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at
    RE: Post Create plugin step - record does not exist

    Hi Roxanna ,


    Could you please confirm the logical name of below line, I guess it should be "account" instead "new_document"

    RegardingObjectId = new EntityReference("new_document", entAccountID)
    RegardingObjectId = new EntityReference("account", entAccountID)


    Thanks 
    Hemant

  • Suggested answer
    Goutham A Profile Picture
    2 on at
    RE: Post Create plugin step - record does not exist

    I see your code is fine .I believe your if condition is returning false,

    Can you please place                

    string strURL = GetLocation(iService,typeofDocument,entAccount.Id);

    inside if loop ( if (entAccount.LogicalName == "new_document")) and see if the error still persists.  get some values via tracing inside if loop

  • Suggested answer
    Vahid Samimi Profile Picture
    210 on at
    RE: Post Create plugin step - record does not exist

    your if condition  if (entAccount.LogicalName == "new_document") check the logical name and is correct but your call function GetLocation(iService,typeofDocument,entAccount.Id)  out of this condition and is posible your logical name not new_document and the id not correct for this regarding object

  • Community Member Profile Picture
    on at
    RE: Post Create plugin step - record does not exist

    Were you able to resolve this issue? I am seeing the same behavior.

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: Post Create plugin step - record does not exist

    Tried post image as well. It's still the same error.

    Here is what I tried:

                if (iContext.InputParameters.Contains("Target") &&
        iContext.InputParameters["Target"] is Entity && iContext.MessageName.ToLower() == "create")
                {

                    Entity postMessageImage;
                    postMessageImage = (Entity)iContext.PostEntityImages["postImage"];
                    if (iContext.PostEntityImages.Contains("postImage") && iContext.PostEntityImages["postImage"] is Entity)
                    {
                       
                        //typeofDocument = postMessageImage.Attributes["new_typeofdocument"].ToString();
                        EntityReference documenttypeId = (EntityReference)postMessageImage.Attributes["new_typeofdocument"];

                        Entity newdocumentType = new Entity("new_documenttype");
                        newdocumentType.Attributes = new AttributeCollection();

                        Entity documentTypeName = iService.Retrieve("new_documenttype", documenttypeId.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_documenttype"));
                        typeofDocument = documentTypeName.Attributes["new_documenttype"].ToString();
                        //accountnumber = (String)postMessageImage.Attributes["accountnumber"];

                    }


                    string strSharePointURL = GetSharePointLocation(iService, postMessageImage.Id, typeofDocument);

                }

            }


    Thanks.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Post Create plugin step - record does not exist

    Hi roxanna,

        Try using a post entity image in your plugin. That should have the entity id of the "new_document" record you have just created. Your plugin should fire post-create.

    https://msdn.microsoft.com/en-us/library/gg309673.aspx

    Hope that helps.

    John

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: Post Create plugin step - record does not exist

    The error just says: new_document 'xxxx-xxx -xxxxxxxx' does not exist.

    That guid is nothing but entAccount.Id that I am getting it from target entity.

    I even tried setting it as update plugin with post opertion.. so that only after the document gets created, I am triggering the plugin. But I still get the same error. Not sure what else to troubleshoot.

    Thanks.

  • ScottDurow Profile Picture
    21 on at
    RE: Post Create plugin step - record does not exist

    Could you post the exact error you get - the code looks like you are doing the right things.

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 CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans