Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

(0) ShareShare
ReportReport
Posted on by 3,614

I've following code snippet in which I am trying to get current order id. But it throw exception, following is the exception and plugin step. Can anyone please guide what went wrong in it?

IPluginExecutionContext context = (IPluginExecutionContext)isp.GetService(typeof (IPluginExecutionContext));
                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)isp.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);
                Entity entity = null;
                entity = (Entity)context.InputParameters["Target"];
                Guid orderId = entity.Id;


Exception.JPG plugin-step.JPG

*This post is locked for comments

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    We are following a custom Order number format.

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    When you say expected and received Order. How these two are related within CRM?

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    It is on change of a lookup field. But I can see that it was invoked twice and the order form also asked to save changes both time.

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    Is this a sync worklfow or async one? Because I am thinking there might be issue in debugging itself while the code is working as expected.

    Can you try updating one field in the Entity and see if it get properly reflected in CRM. Dont debug, just call the update of same record with one field value in the code.

    Thanks,

    PS

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    yes, I tried and it give me the name of order. Expected: '7639065', Received: '7154990'

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    Can you try retrieving the order details with this guid and check it again?

    Entity orderEntity = service.Retrieve("salesorder", entity.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet("name");
  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    Nithya, thank you for response. It gives me GUID but not of that order from which it is invoked

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    Hi Mohsin Ali,

    Try using the code below.

     if ((context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference))
     {
        EntityReference entity = (EntityReference)context.InputParameters["Target"];
        Guid id= entity.Id;
     }

    This code worked for me.

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,614 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    It is simple action process without any input/output parameters. As you can see from step screenshot I trigger plugin when action is invoked. Also, this action is invoked by a workflow.

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: PrimaryEntityId giving wrong Guid in dynamics crm 2016 plugin

    How do you start the Action (and pass the record details)?

    Do you have any input parameter?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

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