web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

config : Hardcoded URLs in javascript

(0) ShareShare
ReportReport
Posted on by 735

I have a problem where there are URLs hardcoded in a JavaScript web resource.  The problem with this is that when taking a cut from production to other environments, these carry the production URLs with them. The other issue is that when performing releases from Dev’s upwards, the release team need to manually go into the JavaScript and update the URLs.

Am looking for a solution in which this is not hardcoded and requires the JavaScript to update each time we release. I’m looking for a generic approach to do this to avoid  hard coding URLs.

Example of the hardcoded webresource

function exampleSearch() {
    var devUrl = "https://namedev.crm4.dynamics.com/";
    var uatUrl = "https://nameuat.crm4.dynamics.com/";
    var prodUrl = "https://name.crm4.dynamics.com/";
    var bauUrl = "https://namebau.crm4.dynamics.com/";

    var serverUrl = Xrm.Page.context.getServerUrl();

    if (serverUrl == devUrl) {
        url = "https://devui.namecloud.com/examplesearch";
    }
    else if (serverUrl == uatUrl) {
        url = "https://nameuatui.namecloud.com/examplesearch";
    }
    else if (serverUrl == prodUrl) {
        url = "https://namecrm.namecloud.com/examplesearch";
    }
    else if (serverUrl == bauUrl) {
        url = "https://nameuui.namecloud.com/examplesearch";
    }

    launch(url);
}

function launch(url) {
    var w = 785, h = 650;
    var left = (screen.width) ? (screen.width - w) / 2 : 0;
    var top = (screen.height) ? (screen.height - h) / 2 : 0;
    window.open(url, "w1", "resizable=no,toolbar=no,scrollbars=no,menubar=no,status=no,directories=no,width=" + w + ",height=" + h + ",left=" + left + ",top=" + top);
}

Am using dynamics online

 

 

*This post is locked for comments

I have the same question (0)
  • johny_crm Profile Picture
    735 on at
    RE: config : Hardcoded URLs in javascript

    Thanks Jason.  Will try the action suggestion .

  • Verified answer
    jlattimer Profile Picture
    24,562 on at
    RE: config : Hardcoded URLs in javascript

    Here is an example of calling an Action from JS (disregard the input/cloning stuff):

    http://xrmguy.com/2014/03/10/crm-2013-actions-are-my-new-favorite-feature/

    And here using the REST endpoint from JS to retrieve a single record:

    http://msdn.microsoft.com/en-us/library/gg334427.aspx

  • johny_crm Profile Picture
    735 on at
    RE: config : Hardcoded URLs in javascript

    Thanks Jason

    Do you have a link i can follow as not not sure how to go about the two suggestions.

    and as a 3rd option would it work by having havascript that accepts a parameter which is passed  into it and do you know how this would be done

  • Verified answer
    jlattimer Profile Picture
    24,562 on at
    RE: config : Hardcoded URLs in javascript

    One option would be to use a config entity - simple entity that holds the value(s). Since this is data it could be different in each environment. When you need it in your JavaScript, retrieve the record and read the value. 

    if you are using 2013, you could do something similar with a custom Action - set the return values from the Action to return you value(s) and then execute the Action from JavaScript to get the results. This is a more solution aware method and doesn't require a new entity.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans