web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Create Plugin

(0) ShareShare
ReportReport
Posted on by

Can anyone please help on creating plugin

whenever account is created or updated. we want to update field called acountid

whenever acountnum changes, fire a plugin which goes and gets guid of number that are in
acountnum then update acountid field

*This post is locked for comments

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    What is your requirement, accountid hold primary key of the account record, whey you want to do that?

  • Community Member Profile Picture
    on at

    so whenver account id will be created or updated, plugin should be fired. and a message box will show the guid, can you help me on this please

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    Is your account id is a custom field or you are referring the default accountid?

  • ram r Profile Picture
    on at

    Hi, Provide more info.

    If accountid is a custom field then you can do this and if its an OOB field then you cannot update the guid.

    docs.microsoft.com/.../sample-create-basic-plugin

  • Community Member Profile Picture
    on at

    Hello Alex,

    whenever account is created or updated. we want to update field called parentacountid

    whenever parentacountnumber changes, we want to fire a plugin which goes and gets guid of number that are in parentacountnumber then update parentacountid field

  • Community Member Profile Picture
    on at

    The requirement is -

    whenever account is created or updated. we want to update field called parentacountid

    whenever parentacountnumber changes, we want to fire a plugin which goes and gets guid of number that are in parentacountnumber then update parentacountid field

  • Suggested answer
    ram r Profile Picture
    on at

    Register a plugin on preoperation stage on create and update messages. Filtering attribute for update will be parentaccountnumber

    Use retrievemultiple(fetchxml/queryexpression) to retrieve account based on account number. Set the retrieved account to parentaccountid lookup.  

    Retrieve multiple www.magnetismsolutions.com/.../dynamics_crm_2011_querying_data_using_fetchxml

    Set lookup value  => entity["parentaccountid"] = new EntityReference("account", <GUID>);

    Develop a plugin docs.microsoft.com/.../sample-create-basic-plugin

    Register a plugin docs.microsoft.com/.../walkthrough-register-plugin-using-plugin-registration-tool

    Edit: Note that in preoperation no need to explicitly call service.update

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    In addition to plugin you can also write js code for this, you can write a web api retrievemultiple call and set parent lookup

    http://himbap.com/blog/?p=2012

    //you can setup lookup using following code:

    var lookupValue = new Array();

          lookupValue[0] = new Object();

          lookupValue[0].id = id;  //returned from query

          lookupValue[0].name = name;

          lookupValue[0].entityType = entityType;

          Xrm.Page.getAttribute("parentacountid").setValue(lookupValue);

    Apart from that you can use this workflow solution as well, just import and use it: www.itaintboring.com/.../dynamics-crm-use-a-workflow-to-set-a-lookup

  • Community Member Profile Picture
    on at

    Hi Ramanathan,

    Is this plugin looking authentic. please confirm.

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

                   {

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

                       if (account != null)

                       {

                           if (account.Attributes.Contains("parentaccountnumber") && account.Attributes["parentaccountnumber"] != null)

                           {

                               string ParentAccountNumber = null;

                               EntityReference entRef = (EntityReference)account.Attributes["parentaccountnumber"];

                               if (entRef.LogicalName == "account")

                               {

                                   Guid accountid = entRef.Id;

                                   string fetchQuery = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

       <entity name='account'>

       <attribute name='accountnumber' />

       <attribute name='accountid' />

       <filter type='and'>

       <condition attribute='aac_parentaccountnumber' operator='not-null' />

       </filter>

     </entity>

    </fetch>", accountid.ToString());

                                   fetchQuery = string.Format(fetchQuery);

                                   EntityCollection FetchParentAccountNumberResult = (EntityCollection)service.RetrieveMultiple(new FetchExpression(fetchQuery));

                                   if (FetchParentAccountNumberResult != null && FetchParentAccountNumberResult.Entities.Count >0)

                                   {

                                       foreach (Entity ent in FetchParentAccountNumberResult.Entities)

                                       {

                                           if(ent.Attributes.Contains("parentaccountnumber") && ent.Attributes["parentaccountnumber"] != null)

                                           {

                                               ParentAccountNumber = ent.Attributes["parentaccountnumber"].ToString();

                                           }

                                       }

                                   }

                               }

                               Entity acc = new Entity("account");

                               acc.Id = account.Id;

                               acc["parentaccountnumber"] = ParentAccountNumber;

                               service.Update(acc);

                               service.Create(acc);

                           }

                       }

                   }

               }

               catch (Exception e)

               {

                   tracingService.Trace("FilteringAttributeForUpdate", e.ToString());

                   throw;

               }

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi, you cant create duplicate account with same account id

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans