Run action in plugin

Find below a method that will execute an Action in CRM based on the parameters received

        /// <summary>
        /// Trigger an Action in CRM. "parameters" parameter can be optional based on the action called, same for "targetEntity".
        /// </summary>
        /// <param name="ActionName"></param>
        /// <param name="TargetEntity"></param>
        /// <param name="service"></param>
        public static void CallAction(string actionName, StringDictionary parameters, EntityReference targetEntity, IOrganizationService service)
        {
            OrganizationRequest Request = new OrganizationRequest(actionName);

            // Global Actions does not require Target. If not global, You should send a record of the same type of the Action's Entity.
            Request["Target"] = targetEntity;
            OrganizationResponse Response = service.Execute(Request);

            // NOTE: In case that your action is expecting a parameter, send it as the example: Request["<MyParameter>"] = "This is a string parameter sent to the action "; 
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s