locked
How to declare CRM Wide JavaScript Global Variables??? RRS feed

  • Question

  • I've a web hosted on my CRM Server http://crm:90 which contain .aspx pages...I use AJAX calls to http://crm:90 through JavaScript to perform operations needed on onChange, onLoad, onSave events in CRM. Having several entities, I've to call several pages using this address,,,,but if this address changes, i've to change its calls on too many places. How can i avoid hard-coding its address into my code? Can use declare a global variable which can be accessible from all of the CRM event? Any workaround???
    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Thursday, December 3, 2009 7:41 PM

Answers

All replies

  • It's something we all would like to see but is not available in this version.
    Thursday, December 3, 2009 8:25 PM
  • Hi Sohaib,

    I have not worked on IFD, but still cant you use a config file to store the server name, instead of hardcoding the server name on too many files.

    Thanks
    Joe
    Friday, December 4, 2009 2:40 AM
  • one way might be to place it in a common library - see http://mscrmblogger.com/2009/10/13/crm-common-javascript-file/ 

    this isn't dependent on the server url name, so couldn't you add it in the common area and reference it from there?



    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    Friday, December 4, 2009 2:54 AM
    Moderator
  • hi scott,

    your solution sounds practical. I am using almost a similar solution right now i.e. I've made a virtual directory and have placed .js file on its source. Now i access this file in my JavaScript code using http://jsfiles:200/common.js .... but again, if i've to change the javascript virtual directory address, i've to change it on every onChange, onLoad, onSave event of all the entities. any workaround?
    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Friday, December 4, 2009 5:40 AM
  • I was thinking you would /not/ create a virtual directory and just reference "/isv/common.js" - but also, I remembered that there is a global variable for the server_url you can use:

    Try this to see what value is returned:  
    alert("SERVER_URL="+SERVER_URL );

    See http://blog.customereffective.com/blog/2008/09/crm-40-global-j.html for more info.



    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    Friday, December 4, 2009 8:47 AM
    Moderator
  • one way might be to place it in a common library - see http://mscrmblogger.com/2009/10/13/crm-common-javascript-file/ 

    this isn't dependent on the server url name, so couldn't you add it in the common area and reference it from there?



    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell

    Isn't common script file unsupported?  What's the risk?
    Friday, December 4, 2009 5:11 PM
  • Mardukes - that's correct, if you have problems accessing the jscript file, MSFT is not going to troubleshoot it for you and they aren't going to "guarantee" that a future update won't 'break' it. - however, it's a pretty common thing to do and it's not a modification of any CRM file (as some sources suggest).

    Regardless, the other method (using the SERVER_URL variable) is probably a better solution for Sohaib's original question.


    Scott Sewell, CustomerEffective | http:\\blog.CustomerEffective.com | Twitter:@ScottSewell
    Friday, December 4, 2009 5:52 PM
    Moderator