locked
Plugin to call jscript functions RRS feed

  • Question

  • Hello Everyone,

    I have a jscript function that fires on the phone call entity. It checks if the recipient field is an account and if so it gets the state of the account and populates it on the phone call entity. This way I can display the state of the account in a view when we use quick campaigns. The obvious issue though is that this doesn't fire on creation.

    Would it be possible to create a plugin that fires on creation of the phone call that just calls the jscript functions I already have to populate the state field? I have zero C# experience but I figure if something like this is possible. I can figure out the on creation code and use jscript I already have that works. The reason I ask is because when I have visual studio open and a new plugin file created I can add a "new item" being a "javascript file".

    Thanks!

    Monday, October 21, 2013 5:03 PM

Answers

  • A plugin inside CRM 2011 is always a .NET method that will be executed (written using C# or VB.NET), inside Visual Studio you create a solution/project to hold your .NET logic file (in your case the Plugin.cs file), but Visual Studio permits to add any files or folders inside a solution (for example an excel file or an mp3) also if they are not relevant to the target of the project.

    Basically you can't call your jscript functions from a plugin also if the file is added in your solution, because you are mixing server side with client side technology.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, October 21, 2013 6:16 PM

All replies

  • Hi,
    a plugin can't execute javascript code registered inside onload/onchange/onsave events. JavaScript code is executed only when the record is opened inside a web browser.

    Depends on the logic you want to implement, it's possible to use C# to fill a field inside a plugin, but depends on the exact logic (what is doing and when is doing the changes)

     

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, October 21, 2013 5:09 PM
  • Hey, thanks for the response. I had guessed what you were saying about not being able to call the jscript from onload/onchange/onsave. What I was curious about is inside the plugin when working in visual studio you have the option to add a new item to the plugin file which can be a javascript file. Would I be able to put my jscript code in that file and be called from the main plugin code. I guess I'm thinking everything would be contained within the plugin but I would be able to use the jscript I already have by adding that new item - javascript file. Trying to show what I'm talking about with the pic below. Could I call the functions from the plugin.cs if i put my jscript in the javascript2.js file? I'm sure this is a very beginner question but I'm just trying to begin teaching myself this.

    Thanks for the help and info!

    Monday, October 21, 2013 5:18 PM
  • A plugin inside CRM 2011 is always a .NET method that will be executed (written using C# or VB.NET), inside Visual Studio you create a solution/project to hold your .NET logic file (in your case the Plugin.cs file), but Visual Studio permits to add any files or folders inside a solution (for example an excel file or an mp3) also if they are not relevant to the target of the project.

    Basically you can't call your jscript functions from a plugin also if the file is added in your solution, because you are mixing server side with client side technology.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Monday, October 21, 2013 6:16 PM
  • Alright that's unfortunate but makes sense. Thanks for the explanation.
    Monday, October 21, 2013 6:43 PM