locked
CRM 2011: Customization with JavaScript: How can I softcode the server name on URL's? RRS feed

  • Question

  • I'm wondering how others might be setting the URLs that are used by JavaScript for different environments.  When I deploy to DEV/TST/PRD, the JavaScript that I am using has to be adjusted for each environment because I'm calling out to an external web service for some of my methods.  That external service has to have the server name in the URL. So I wonder what is the best way to soft-code the server name in my URL so that I do not have to modify anything when I deploy the solutions to different environments?

    I do have an entity called admin configurations, where I store a number of admin settings.  So I could put it there.  But then I would have to make a call out to CRM just to get it. That's ok and probably what I will end up doing so that I don't have to reset the JavaScript each time I deploy.  But I was thinking about maybe storing it in a separate JavaScript file that I do not deploy, maybe set it somewhere else.  So I'm just curious what others are doing in this regards and what has worked well for them.

    Any suggestions or ideas are much appreciated.

    Best regards,

     

    Jon Gregory Rothlander



    Tuesday, December 2, 2014 7:28 PM

Answers

  • Hi,

    I think you can have two options for this.

    - Pass the Server name to JavaScript methods as parameter. This will require you to open every form where you are calling JS and change server name.

    - Configuration entity that you have mentioned. We always prefer this option. I know it will increase call but to make it dynamic this could be last option.

    Please let us know if you find any other option.

    Thanks!

    Kalim Khan

    • Marked as answer by jonrothlander Wednesday, January 7, 2015 7:16 PM
    Wednesday, December 3, 2014 6:20 AM

All replies

  • Tuesday, December 2, 2014 8:46 PM
    Moderator
  • Jason,

    Thanks for you reply.  That might work in 2013, but I'm in 2011. Sorry for not mentioning that. I typically mention that in the title. Also, that 2013 solution probably wouldn't work well for me because I have dozens of configuration settings in my configuration entity and managing through Custom Actions in 2013 sounds like would be painful. So probably even when I get to 2013 I'll still end up with the configuration entity.

    That said, it sounds like in 2012 the best option for my JavaScript is to just make a separate call to CRM to pull the server URL for the web service, construct the URL, then call the other service. That is workable, I was just wanting some suggestions in case there are other options that might perform a little better.

    Best regards,

      

    Jon Gregory Rothlander

    Tuesday, December 2, 2014 10:13 PM
  • Hi,

    I think you can have two options for this.

    - Pass the Server name to JavaScript methods as parameter. This will require you to open every form where you are calling JS and change server name.

    - Configuration entity that you have mentioned. We always prefer this option. I know it will increase call but to make it dynamic this could be last option.

    Please let us know if you find any other option.

    Thanks!

    Kalim Khan

    • Marked as answer by jonrothlander Wednesday, January 7, 2015 7:16 PM
    Wednesday, December 3, 2014 6:20 AM
  • @Kalim Khan

    Yes, I was trying to avoid that but I don't see any other choice.  What I actually ended up doing was create function to call out and pull it from CRM config setting.  Then I modified the JavaScript code to just call out to that function to get the path.  It's fast.  Seems to work just as fast as hardcoding it, but I know there is certainly some delay to pull it.  But the uses will never notice.

    Thanks for your help and suggestions...


    Jon Gregory Rothlander

    Wednesday, January 7, 2015 7:18 PM