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)

Entity Id must be specified for Update

(0) ShareShare
ReportReport
Posted on by 1,562

I am trying to update description on win event in opportunity.

Its giving error,please suggest me where i am lacking.

error:"Entity Id must be specified for Update".

code:

if (localContext == null)
{
throw new ArgumentNullException("localContext");
}

IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;

if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];

if (entity.LogicalName == "opportunity")
{
if (!entity.Attributes.Contains("description"))
{
try
{
entity.Attributes.Add("description", "Opportunity status changed");
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("GenerateOpportunityAutoNumber plugin error: ", ex);
}
}
}
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nghieppham Profile Picture
    4,755 on at
    RE: Entity Id must be specified for Update

    Hi Tin Lat,

    Please check the event pipeline that you register for this step. Please change to Pre-Operation, because if you are using post-operation, this record has been change to Close, you cannot update it.

    And 1 note, You have add OpportunityId to your code, I do not see this line code.

    entity.Attributes["opportunityid"] = "YourId"

    Regards,

  • Tin Profile Picture
    1,562 on at
    RE: Entity Id must be specified for Update

    its executing preparation,how can add oppId here can you share me code?

  • nghieppham Profile Picture
    4,755 on at
    RE: Entity Id must be specified for Update

    Hi Tin,

    Entity entity = (Entity)context.InputParameters["Target"];

    You just get from entity["Attribute"] or you can get from context like ((Entity)context.InputParameters["Target"]).Id

  • Community Member Profile Picture
    on at
    RE: Entity Id must be specified for Update

    Hi Tin,

    Can you provide the entire trace you received (you can download the log file on error and that should have it). Also, I do not think you will need to explicitly specify the id for the entity since you are updating the same entity and the context will already have an id specified.

  • Tin Profile Picture
    1,562 on at
    RE: Entity Id must be specified for Update

    yes Shaik i also thinking same.....

    I am calling plugin on 'win' message and tried to update opportunity description only.

    Its very simple thing i want to do....but dont know why getting error.

    this is error log i found,please have a look:

    <s:Envelope xmlns:s="schemas.xmlsoap.org/.../&quot;><s:Body><s:Fault><faultcode>s:

    Client</faultcode><faultstring xml:lang="en-US">Entity Id must be specified for Update</faultstring><detail><OrganizationServiceFault xmlns="schemas.microsoft.com/.../Contracts&quot; xmlns:i="www.w3.org/.../XMLSchema-instance&quot;><ErrorCode>-2147220989</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic&quot;><KeyValuePairOfstringanyType><a:key>ValidationPath</a:key><a:value i:type="b:string" xmlns:b="www.w3.org/.../XMLSchema&quot;>/0</a:value></KeyValuePairOfstringanyType></ErrorDetails><Message>Entity Id must be specified for Update</Message><Timestamp>2016-04-04T11:01:16.1232311Z</Timestamp><InnerFault><ErrorCode>-2147220970</ErrorCode><ErrorDetails xmlns:a="schemas.datacontract.org/.../System.Collections.Generic&quot;/><Message>System.ArgumentException: Entity Id must be specified for Update

    Parameter name: Target</Message><Timestamp>2016-04-04T11:01:16.1232311Z</Timestamp><InnerFault i:nil="true"/><TraceText i:nil="true"/></InnerFault><TraceText>

    [CrmPackageforBhawik.PluginsforBhawik: CrmPackageforBhawik.PluginsforBhawik.PreOpportunityWin]

    [9e9ad9ac-52fa-e511-80ce-0050569e09d5: PreOpportunityWin]

    Entered CrmPackageforBhawik.PluginsforBhawik.PreOpportunityWin.Execute(), Correlation Id: 70f53635-cce4-42e3-9553-42c67ee70ccc, Initiating User: a0f456a2-9d67-e511-80cd-0050569e09d5

    CrmPackageforBhawik.PluginsforBhawik.PreOpportunityWin is firing for Entity: opportunity, Message: Win, Correlation Id: 70f53635-cce4-42e3-9553-42c67ee70ccc, Initiating User: a0f456a2-9d67-e511-80cd-0050569e09d5

    Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Entity Id must be specified for Update (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

    Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Entity Id must be specified for Update (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault)., Correlation Id: 70f53635-cce4-42e3-9553-42c67ee70ccc, Initiating User: a0f456a2-9d67-e511-80cd-0050569e09d5

    Exiting CrmPackageforBhawik.PluginsforBhawik.PreOpportunityWin.Execute(), Correlation Id: 70f53635-cce4-42e3-9553-42c67ee70ccc, Initiating User: a0f456a2-9d67-e511-80cd-0050569e09d5

    </TraceText></OrganizationServiceFault></detail></s:Fault></s:Body></s:Envelope>

  • Tin Profile Picture
    1,562 on at
    RE: Entity Id must be specified for Update

     protected void ExecutePreOpportunityWin(LocalPluginContext localContext)

           {

               if (localContext == null)

               {

                   throw new ArgumentNullException("localContext");

               }

               IPluginExecutionContext context = localContext.PluginExecutionContext;

               IOrganizationService service = localContext.OrganizationService;

               if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)

               {

                   Entity entity = (Entity)context.InputParameters["Target"];

                   if (entity.LogicalName == "opportunity")

                   {

                       if (!entity.Attributes.Contains("description"))

                       {

                           try

                           {                          

                              entity.Attributes["description"] = "Opportunity status changed";

                              entity.Attributes["opportunityid"] = ((Entity)context.InputParameters["Target"]).Id;

                           }

                           catch (FaultException ex)

                           {

                               throw new InvalidPluginExecutionException("GenerateOpportunityAutoNumber plugin error: ", ex);

                           }

                       }

                   }

               }      

    Even this is not working ...............where i am wrong please correct.....this is the complete code which i am using for update.

  • Suggested answer
    Nuno Profile Picture
    2,005 on at
    RE: Entity Id must be specified for Update

    Hi,

    I would advise you to register your plugin on win message.

    The way for you to get the Id of the opportunity it described in this link:

    simplicitypoint.wordpress.com/.../getting-the-opportunity-entity-in-plugin-when-closing-as-won

    After you have the Id of your opportunity you are able to update it.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans