Call C # code from JScript CRM Online 2011 feed

I need some code to be executed when the ribbon button is clicked on an entity that updates some related data from CRM Online 2011. I would prefer not to write all this logic in JScript. Is there a way to call C # code from JScript? I looked at the JScript file that Microsoft uses from the tape and looks like this:

Mscrm.Campaign.copyCampaign = function (campaignId, saveAsTemplate) { var $v_0 = new RemoteCommand("MarketingAutomation", "CopyCampaign", null); $v_0.SetParameter("campaignId", campaignId); $v_0.SetParameter("saveAsTemplate", saveAsTemplate.toString()); var $v_1 = $v_0.Execute(), $v_2 = $v_1.ReturnValue; openObj(Mscrm.EntityTypeCode.Campaign, $v_2, null, null, Mscrm.NavigationMode.NavigationModeInline, null); Mscrm.Utilities.refreshParentGrid(Mscrm.EntityTypeCode.Campaign, campaignId) }; 

I see that the RemoteCommand call is being removed, which I believe is returning to some web service function. I hope to do something like this. Can I add my own web service features?

I managed to call from JScript to send an “Assign” message to an object in the same way as a test. This could potentially work with the plugin, but it seems strange to send a message for a run event that actually didn’t just happen to run some C # codes ("Assign", "Update", etc.), and I don’t know t see a way to create your own messages.

+8
javascript c # dynamics-crm dynamics-crm-2011 dynamics-crm-online
source share
5 answers

You cannot add your own web services or create your own plugin posts in 2011. The best way we found is as follows:

  • Create an entity that exists solely to run custom code on the server.
  • Assign it attributes called the message name and another property to pass parameters in any format you choose (XML, JSON, etc.).
  • From your JavaScript, create an instance of this object that passes the correct parameters.
  • Connect the plugin to the Create message of this object, and then it reads the parameters and executes any desired code.

As long as an Assign message is just randomly transmitted or something might work, it is probably not supported by Microsoft through the eyes, and it would be difficult to debug if anyone else ever had to look at this system.

+9
source share

There is another way: insert two options into the form, when you click the user button that you created on the ribbon, make two values ​​for the true parameter, then run the form save method in the plugin that you created for the entity to check whether the value of the two parameters is true, and then run your codes, then again change the value of the two parameters to false. also in the form you can make two features invisible.

+4
source share
+1
source share

ok, writing a lot of JavaScript logic is a mess to think about, but creating js code that runs the “real” logic using the create operation (more or less the command line) will also lead to a difficult decision.

Depending on the level of complexity and requirements (for example, it is not possible to perform operations to maintain another user in js), I always prefer the pure js approach. To reduce complexity, try a library that provides kernel functionality:

Crrmrestkit

XrmServiceToolkit

Good luck

Daniel

+1
source share

I'm late to the party here, but just to simplify things for people considering this topic for the newest version of CRM (because it is labeled crm online): There is currently something called "Action" that can be created like this same as Workflow or Business Process Flow. You can specify input and output parameters for this action. Main advantages:

  • you can register a plugin for this action, so instead of running jScript logic you can run some C # logic

  • you can call this action using webAPI

As for CRM 2011, although it is already quite outdated - a better approach than suggested in the action taken is to run your logic on the RetrieveMutliple post of your custom object so that you avoid creating / deleting some magic entries (and users will only have to have read rights for them, not create or update).

0
source share

All Articles