Sunday, February 1, 2015

Faking JavaScript Codelessly

I am quite a fan of not using code where possible and where practical. However, there is no point sacrificing code if the user experience makes the system unusable. CRM 2013/2015 gives us a few tools in our kitbag for avoiding using code without sacrificing experience. I thought I would explore them.

Real-Time Workflows

I am so pleased to see real-time workflows in CRM. In the old days, workflows could only run in the back end. The problem with this is while you could make them do lots of interesting things (Auto-numbering, Lead Assignment and Counters, for example), the user experience was sub-par. The main problem was that while the workflow did everything you wanted it to, the user did not know what was happening because it was all on the server and not on the form. This has now changed with real-time workflows.

Any workflow can be converted to run in real-time by deactivating it and hitting the ‘Convert to a real-time workflow’ button at the top of the form.

image

I made of use of real-time workflows in my address finder article. The experience in that case was, once the location was set, the other fields appeared updated on the save of the record. In other words, if you are looking for something which behaves in a similar way to the OnSave event, a real-time workflow gets us close.

So what other events can JavaScript trigger off? You will remember from my Developer Essentials article that JavaScript triggers off of four events:

  • OnSave (saving of the form)
  • OnLoad (when the form opens on the screen)
  • OnChange (when the value in a field changes)
  • TabStateChange (opening and closing of Tabs)

So we have covered off the first one. What about the others? For these we will need Business Rules.

Business Rules

Another new function for CRM 2013/2015, Business Rules allow us to configure form behaviours. I mentioned Business Rules in my updated Auto-Number post from last year. Business Rules are configured on the form and here is a simple one I set up to test the behaviour. In this case, when the Main Phone is populated, the value is copied to the Other Phone field.

image

When activated, it becomes clear Business Rules run on both the OnLoad event (on loading the form, if the Main Phone had a value and the Other Phone did not, the value was copied) and OnChange event (if I changed the Main Phone value and tabbed out of the field, it was immediately copied to the Other Phone field). Please note that, with Business Rules, synchronous plugins run first and then the Business Rules fire in the order they were activated (oldest to newest). Also, in 2015, Business Rules were changed to fire server side, not client side (as they did for 2013). This means if a value changes in the back end (via integration, for example) the rule will fire without the need for opening the record. From a user’s perspective, it still appears as if the rule is firing OnLoad and OnChange.

Tab State Changes and Other Stuff

There are no codeless equivalents for triggering off the opening or closing of a Tab and there are plenty of other things you may need to do which simply cannot be done with the limited actions available for Workflows and Business Rules. In these cases you will still need Javascript.

Also, as a word of warning, with the many ways to emulate JavaScript-like behaviour, it can be difficult to determine exactly how a form does what it does. For this reason I know of a few senior developers who prefer to use JavaScript in all cases, even though the codeless alternatives may be quicker and as effective. In their case they are considering the future administration of the form. If everything, or nearly everything can be contained in one place, it is easier for an administrator; no rifling through numerous places trying to find the right thing to change.

Conclusions

If you are upgrading and have a system with lots of code, there is plenty of opportunity with the improved functionality of CRM 2013/2015 to remove some of that code and replace it with configuration (especially if it is breaking in going from CRM 2011). Similarly if, like me, your coding days are a bit of a distant memory, the new functionality gives you something to impress clients and potential clients with when showing off what is possible with CRM forms and making them user friendly. Try them out and see how easy it is to configure what used to be coded.

1 comment:

Unknown said...

Thanks Leon, great article. Business Rules is certainly a great start, and for anyone who needs more power and flexibility than that can look at CRM Rules from Visionary Software. It takes Business Rules to a whole other level - all with no coding! Thanks again for the article.