Using Chrome to help write Client Side Scripts

1 minute read time.

What I find is so useful about the Chrome developer console is that it lets you edit JavaScript code on the fly and so is a very good way of starting to evolve a business rule that needs to be written in the Custom Content field or even an onChange script.

In the image above you can see how I have been working out the code I need to run in order to implement the business rule "When a Company is Changed to be a Prospect the Service Level ID should be set to Silver."

The code do that in the new API is is this

[code language="javascript"]
if (crm.fields('comp_type').value()=='Prospect'){crm.fields('comp_slaid').value('2')}

But another reason I love working with Chrome is that it helps me investigate the structure of the web pages generated by Sage CRM. For example if I want to understand how to identify a field in the Company Phone/Email tab I can just highlight any field (or any page of the screen), right click the selection, and choose Inspect Element.

Chrome will open the Developer Tools straight away and show the elements.

I chose the Phone/Email screen as an example it may seem very hard to add behaviour into this screen but in Sage CRM using the API it is actually quite easy. But that is a subject for another article.

  • Nice article Jeff.

    I've found that one of the more very basic, but really useful, parts of this is being able to print out to the console log.

    Instead of having to generate a load of JavaScript alerts to debug your code (never fun if you do it inside a loop), you can just do something like this:

    console.log("Value of field is: " + crm("comp_name").value());

    Really useful for troubleshooting.