Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C# Code from Ribbon JScript CRM Online 2011

I need to have some code execute on the click of the ribbon button on an entity that updates some related data from CRM Online 2011. I would prefer not to have to write all of this logic in JScript. Is there a way to call into C# code from JScript? I have looked at the JScript file Microsoft is using from the ribbon and it 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 a RemoteCommand call being placed that I assume is going back to some web service function. I am hoping to do something like this. Can I add my own web service functions?

I was able to make a call from JScript to send an "Assign" message for an entity just as a test. This potentially could work with a plugin-in, but it seems odd to send a message for an execution event that did not actually occur just to run some C# code ("Assign", "Update", etc.), and I don't see a way to create your own messages.

like image 432
Chad Avatar asked Feb 23 '11 13:02

Chad


People also ask

What is call in C?

The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.

What is function call in C with example?

During a function call, a function may accept one or more inputs as arguments, process them and return the result to the calling program. For example, in function call sqrt (x), the sqrt function accepts the value of x as input and returns its square root.

What is call by value in C?

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C programming uses call by value to pass arguments.

What is calling and called function in C?

Calling a FunctionWhen a program calls a function, the program control is transferred to the called function. A called function performs a defined task and when its return statement is executed or when its function-ending closing brace is reached, it returns the program control back to the main program.


1 Answers

You can't add your own web services or create your own custom plugin messages in 2011. The best way we've found of doing this is to:

  1. Set up a entity that exists exclusively to run custom code on the server.
  2. Give it attributes called message name and another property to pass in parameters in whatever format you choose (XML, JSON, etc.)
  3. From your JavaScript, create an instance of that entity passing in the correct parameters.
  4. Have a plugin attached to the Create message of that entity, and then it reads in the parameters and executes whatever custom code you'd like.

While just randomly passing in an Assign message or something might work, it's probably unsupported in Microsoft's eyes, and it would be hard as hell to debug if someone else ever had to look at this system.

like image 152
Matt Avatar answered Oct 25 '22 20:10

Matt