Loading and Using Required Form Libraries Programmatically – JavaScript CRM 2013

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”.

Before I continue I would like to give credit to Inogic from the Dynamics Community for providing the code I originally used.

How to load a web resource using JavaScript

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.

loadingWebResources.PNG

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.

JavaScript File Downloadhttps://drive.google.com/open?id=0B3iSv07BXKiOeTRtVzh5WUhSUkE


 

Hope this helped!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.