locked
CRM 2013: Plugin on Update Message, to get all attributes RRS feed

  • Question

  • Dear all,

    I am wrting a plugin which will trigger on the status change, and in that plugin i need to get the Oppotunity Name and Account Name.

    The plugin is registered on Opportunity.

    Can anyone help/guide me how to get the Oppotunity Name & Account name attribute in the plugin.

    Many Thanks & Regards

    Vinay

    Sunday, June 8, 2014 10:49 PM

All replies

  • Hi Vinay,

    I  think you are in SetState or SetStateDynamicEntity messages.In this messages the context does not give you the attributes therefore you must use Pre Or Post İmages due to your Plugin Stage.

    If your plugin works on Update , it is easy to get the attributes.You can also use Pre or Post image.( Context will give you only the changed attributes)

    BTW you registered your plugin on Opportunity , so you can get only the name of opportunity in the images. If you want to get the account name you have to build a query to the Account.


    Polat Aydın Crm Software Developer


    Monday, June 9, 2014 12:18 AM
  • Hi,

    I have build a query to get the parentaccountid as follows, but i get an error on the last line: guidAccount = new Guid(strAccountName)

    QueryExpression queryOpportunity = new QueryExpression
                            {
                                EntityName = "opportunity",
                                ColumnSet = new ColumnSet("name","parentaccountid")
                            };
                            queryOpportunity.Criteria.AddCondition("opportunityid", ConditionOperator.Equal, OppID);
                            EntityCollection resultsOpportunity = service.RetrieveMultiple(queryOpportunity);
                            Entity eOpportunity = new Entity();

                            if (resultsOpportunity.Entities.Count.Equals(1))
                            {

                                eOpportunity = resultsOpportunity.Entities[0];
                                strTerritoryName = eOpportunity.Attributes["name"].ToString();
                                strAccountName = eOpportunity.Attributes["parentaccountid"].ToString();

                                guidAccount = new Guid(strAccountName);   //Error here
                            }

    Can you help please?

    many Thanks

    Monday, June 9, 2014 12:38 AM
  • I do not understand your query. You are in the opportunity entity plugin , so why do you select the opportunity?Crm Gives you these attributes in the Image. You do not need to build a query to Opportunity entity because you are already in Opportunity Entity Plugin

    You should build the query to the account to get Account Attributes. Here is an example with fetchXml.

    string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                                        <entity name='account'>
                                        <attribute name='name'/>                                    
                                        <attribute name='accountid'/>
                                        <order attribute='name' descending='false'/>
                                        <link-entity name='opportunity' from='parentaccountid' to='accountid' alias='ad'>
                                        <filter type='and'>
                                        <condition attribute='opportunityid' operator='eq' uiname='abc' uitype='opportunity' value='{yourguid}'/>
                                        </filter>
                                        </link-entity>
                                        </entity>
                                        </fetch>";
    EntityCollection collect =  Service.RetrieveMultiple(new FetchExpression(fetchXml));


    I also show your error below

    Also eOpportunity.Attributes["parentaccountid"].ToString(); this is wrong because it is entityreference.You can not convert entityreference to Guid.

    ((EntityReference)eOpportunity.Attributes["parentaccountid"]).Id


    Polat Aydın Crm Software Developer

    Monday, June 9, 2014 1:07 AM
  • try this

    Guid Account =strAccountName.ID;

    but you get the value in opportunity only using pre or post image why your using Queryexpression

    I think your retrieving the Customer Name Lookup in Opportunity

    check this Link "http://www.magnetismsolutions.com/blog/roshanmehta/2013/04/23/crm-2011-plugins-obtaining-entity-record-information"


    ms crm

    Monday, June 9, 2014 6:06 AM
  • Hi,

    Can anyone guide/help me how to use the Image in the plugin to trigger on update.

    I am usin the following: 

    // The InputParameters collection contains all the data passed in the message request.
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                {

    is it good?

    Many thanks & Regards

    Vinay

    Monday, June 9, 2014 9:54 AM
  • I suggest you to use Crm developertoolkit. It creates images for you. 

    Also if you do not use CrmDeveloperToolKit , you can get the image like that.I want to remind you , This code for PreImage.

    if (context.PreEntityImages.Contains(“yourimagename”) && context.PreEntityImages["yourimagename"] is Entity)

    {

    preMessageImage = (Entity)context.PreEntityImages["yourimagename"];

    Guid myparentaccountid = Guid.Empty;

    if( preMessageImage.Attributes.Contains("parentaccountid"))

    {

       myparentaccountid = ((EntityReference)preMessageImage["parentaccountid"]).Id

    }

    }


    Polat Aydın Crm Software Developer

    Monday, June 9, 2014 10:32 AM