Something I had quite a bit of trouble figuring out when I set out to make my own CRM solution is ‘how do I use required form libraries without manually adding them to each form?’ or to put it another way ‘is there any way to programmatically load web resources?’ and the answer is “by using the code below” and “yes”.
The code I’ve included below will create a httpRequest which loads a specified web resource, a download for this is included at the bottom of the article.
I’ve commented the code above so it should hopefully be understandable what it’s doing but I’ll give a brief explanation of each major step anyway –
Line 3 - This line simply calls the function 'loadWebResource' and passes a text value which should be the same as the 'Name' of the resource you want to load. Line 12 - This returns the URL for the current deployment of CRM Line 15 - 17 - If statement which uses a regex match to determine if the clientUrl value ends with a '/' and if so it removes it. Line 20 - 22 - Creates a httpRequest to return the specified web resource and then evaluate the response. Line 24 - 27 - This is a catch for any errors encountered whilst trying to load the web resource. Will simply create a line in your browsers console log.
Hope this helped!