Referencing functions in another script on a view

Answered Referencing functions in another script on a view

  • Thursday, June 07, 2012 8:35 AM
     
     

    I have created some custom ribbon buttons which call javascript functions when clicked. These need to reference some other functions that are in a different script. I know that on a form you simply add the library to the form as well but is there any way that this can be done when on a view?

    Thanks

All Replies

  • Thursday, June 07, 2012 11:10 AM
     
     Proposed

    Hi Jimminybob,

    Yes, you can do it by adding one more row inside the <Actions> tag in the ribbon XML.

    you should use it as below

    <Actions>

    <JavaScriptFunction Library=”$webresource:MainJavascript” FunctionName=”Hello”></JavaScriptFunction>

    <JavaScriptFunction Library=”$webresource:SecondJavascript” FunctionName=”isNaN”></JavaScriptFunction> //This you have to add 

    </Actions>

    The second line will be used to the function of other Second javascript library. Please Vote as helpful if it helps you.

    Thanks,

    Shaleen


    • Proposed As Answer by Shaleenb Thursday, June 07, 2012 11:10 AM
    • Unproposed As Answer by Shaleenb Thursday, June 07, 2012 11:10 AM
    • Proposed As Answer by Shaleenb Thursday, June 07, 2012 11:10 AM
    • Edited by Shaleenb Thursday, June 07, 2012 11:11 AM
    •  
  • Thursday, June 07, 2012 1:09 PM
     
     
    Would this also work with enable and disable rules for the button?
  • Thursday, June 07, 2012 1:55 PM
     
     

    Hi Jimminybob,

    I think you can use it i never tried this scenario. Please try it if found it is working please keep posting.

    Thanks,

    Shaleen

  • Friday, June 08, 2012 12:41 PM
     
     
    It doesnt seem to work for enable rules, as soon as the record is selected there is an error and the report says the function is undefined.
  • Friday, June 08, 2012 1:35 PM
     
     Answered Has Code

    If that's the case, you can use the following JavaScript function to load another JavaScript webresource within your JavaScript code.

    All you need to do is to pass the name of the web resource

    For e.g.

    LoadWebResource("new_commonlibrary.js");      

    LoadWebResource = function(resourceName)
    {
    	var httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    	httpRequest.open("GET", "/" + ORG_UNIQUE_NAME + "/webresources/" + resourceName, false);
    	httpRequest.send(null);
    	try
    	{
    		eval(httpRequest.responseText);
    	}
    	catch (e)
    	{
    		alert("Error loading " + resource + ":\n" + e.description);
    	}
    }

    • Marked As Answer by Jimminybob Monday, June 11, 2012 10:34 AM
    •  
  • Monday, June 11, 2012 10:34 AM
     
     
    Brilliant, that works great thanks