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)

Triggering a Plugin from the Ribbon (CRM Online)

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

I'm new to CRM Development, I've been tasked by the company to amend the qualification process that was built by a 3rd party. The qualification process that I'm inheriting qualifies both Leads and Opportunities and is triggered by changes made to a series of related child entities, (though not the parent entities)

We'd like to shift this to a qualify button on a ribbon. Is there a way to trigger plugin code from the ribbon?

We're using CRM 2016 Online, and my searches around the net suggest that custom Workflow activities, and/or custom Actions would achieve what I want, but aren't available when using CRM Online, is there another alternative?

Thanks for your time,

Steven Blom

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Amar Prakash Profile Picture
    565 on at

    Hi Steve,

    I have one suggestion to trigger plugin on ribbon button.

    1. Create a custom field qualify flag or use any existing field

    2. Click on ribbon button update the field #1

    3. Register the plugin on update of field #1

    I think this will solve your problem. Please let me know if you need any help. Thanks.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Steven,

    If you want to Call plugin, then you need to perform below steps :

    1. Create a new two option field

    2. Create a js to be called from ribbon that will change the field value

    3. Create a plugin code to check this two option field is changed or not

    4. Clear the changes so that it will trigger again the plugin

    You can update the field by update that attribute and save it :

    //Update field

    Xrm.Page.getAttribute("fieldname").setValue(value);  

    //Set submit mode to always

    Xrm.Page.getAttribute("fieldname").setSubmitMode("always");

    //Force save

    Xrm.Page.data.entity.save();  

    Replace your attribute name with "fieldname"

  • Community Member Profile Picture
    on at

    Thank you both for your replies.

    Mohit Bansal, Should I reset setSubmitMode after calling .save()?

    If the field is a boolean, and I set it to "true" to trigger the qualification, would it be best to set it to false before the transaction ends, or should I check to see if it's has changed against the Pre-Image/Post-Image?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Steven,

    No need to set it to false and reset setSubmitMode as we are setting setSubmitMode to always then it will call every time when you click on the button.

  • Verified answer
    Bhuvaneswary Rajasekaran Profile Picture
    405 on at

    Hi Steve,

    The straight forward approach to call a plugin through button click is using "Actions". your action should define the request and response param. service name should be like "actionName.pluginName". Plugin should contain the business logic. Your plugin will be registered under the message "actionName". Let me know if you need more clarity.

    Thanks
    Bhuvi

  • Tanguy TOUZARD Profile Picture
    687 Most Valuable Professional on at

    This is the best answer!

    Do not create junkf field just to trigger some code

  • Community Member Profile Picture
    on at

    This was the approach I was expecting to take, but if I'm reading msdn.microsoft.com/.../dn481600.aspx correctly,

    While actions are supported in both Microsoft Dynamics CRM Online 2016 Update and Microsoft Dynamics CRM 2016 (on-premises), creating an action in code (using XAML) is only supported by on-premises and IFD deployments. Online customers must create actions interactively in the web application.

    Suggests that custom actions like this isn't available in CRM Online? Is this not actually the case anymore? I tried to create a custom action in CRM and then tried to use the new message in the Plugin Registration tool and it doesn't seem to pick it up.
  • Community Member Profile Picture
    on at

    Alright, I've finally had a chance to play with it. Creating a custom action works with CRM Online (2016), but it breaks stuff, and It's highly unlikely to be supported.

    If you are sure you want to go down this path, here's what I did:

    Create an Action Process in your solution, take note of the Unique Name, you'll need it later.

    Activate the Action to make it usable.

    You can't create a message using the Plugin Registration tool. It's limited to the built-in messages that CRM provides as far as I can tell, you'll need to write a custom application to do it. You'll need to grab the "Microsoft.CrmSdk.Extensions" NuGet Package.

    I am using Early Bound entities according to the Plugin Registration Entities page on MSDN.

    class Program
    {
    	static void Main(string[] args)
    	{
    		var connection = CrmConnection.Parse(<Enter Your Connection String Here>);			                                      
    		var service = new OrganizationService(connection);
    		var context = new DeployPluginCRMContext(service);
    		var message = context.SdkMessageSet.Single(_ => _.Name == <Unique name of your action>);
    		var messageFilter = context.SdkMessageFilterSet.Single(_ => _.SdkMessageId.Id == message.Id);
    		var pluginType = context.PluginTypeSet.SingleOrDefault(_ => _.Name == <Type of your plugin>);
    		var stepToRecreate = new SdkMessageProcessingStep
    		{
    			FilteringAttributes = "",
    			Name = "Test",
    			Description = "Description",
    			Mode = StepMode.Synchronous,
    			Stage = StepStage.Preoperation,
    			SupportedDeployment = StepSupportedDeployment.ServerOnly,
    			Rank = 1,
    			SdkMessageId = new EntityReference(message.LogicalName, message.Id),
    			SdkMessageFilterId = new EntityReference(messageFilter.LogicalName, messageFilter.Id),
    			PluginTypeId = new EntityReference(pluginType.LogicalName, pluginType.Id)
    		};
    		service.Create(stepToRecreate);
    		Console.ReadLine();
    	}
    }

    When you run it, you will be able to see it in the Plugin Registration tool, but you won't be able to view or edit any of it's possibilities. The Application will throw a MEF composition exception, but at least you'll be able to invoke the action from JavaScript and it should invoke the plugin.

    I have VERY mixed feelings about this solution, but I feel that this is probably less of a bad thing than adding useless fields to an entity.

    Regards,

    Steven

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