CRM Client-Side Scripting Tips


In this section, we will review some useful tips we've discovered when working with client-side scripts. These topics include:

  • Development environment

  • Languages

  • Testing and debugging

  • Additional resources

Development Environment

We recommend that you create your scripts in an external editor instead of attempting to write code directly in the Microsoft CRM Event Detail Properties dialog window. Common script editor choices would be Microsoft Visual Studio .NET, Microsoft Office FrontPage, and Notepad. We recommend that you write your scripts in an external editor for the following reasons:

  • The Enter and Tab keys do not function as expected in the Microsoft CRM text area. This makes it extremely difficult to write well-formatted and easy-to-read code.

  • External editors provide a myriad of tools to assist in development (such as Microsoft IntelliSense, color coding, and integrated debugging). The Microsoft CRM form is simply an HTML form text area that doesn't provide any of these development features.

  • An external editor allows you to use a version control program (such as Microsoft Visual SourceSafe) to archive and back up your scripts.

Languages

Microsoft CRM renders event scripts on the client-side of the browser, so you must use a scripting language compatible with Internet Explorer (such as Microsoft JScript or JavaScript). Microsoft CRM provides no validation of your script; it merely renders the script out to the resulting HTML page. Therefore, you can use the scripting language that you're most comfortable with or that your business logic requires.

Testing and Debugging

Any developer who has received an emergency call on the weekend about a coding or system problem knows the importance of thoroughly testing your code! Because Microsoft CRM does not validate any script code, you are responsible for ensuring that your scripts will work with Microsoft CRM. We recommend the following test techniques when developing your custom scripts:

  • Always test your scripts on a development Microsoft CRM environment and not on production servers.

  • Where possible, set up a simple Web page with a test form, and test your JavaScript outside of Microsoft CRM. This will provide for faster development and debugging. Then copy and paste the final code into the appropriate Microsoft CRM event.

  • Use the Preview command to test your client-side scripts before publishing.

  • If it appears that your code doesn't work as expected, first ensure that you enabled your event. Then, use the alert() method to output various logic points, and try to first eliminate the interaction with Microsoft CRM. In many cases, the flaw may be contained within the code logic itself, independent of the integrated properties of Microsoft CRM.

  • Add an external script reference. You can inject a reference to an external script file from the form's onLoad() event (refer to the examples in this chapter for syntax). This allows you to update the JavaScript directly and test against the actual CRM form on a development server, instead of constantly launching the preview form. We only recommend referencing an external script during the development phase of your project, don't do this in production environments because Microsoft does not support using this technique.

  • When making updates to your script and reviewing them in a preview form, you must close and launch a new preview form with each script change. Microsoft CRM caches the form, so simply refreshing your existing preview form will not show your changes.

  • Always export a backup copy of the entity that you are updating. This allows you to roll back if your updates cause an irreversible error.

  • Be sure to keep backups of your scripts and store them with source control.

Tip 

If you are new to scripting languages, you should be aware that both JavaScript and Jscript are case-senstive. So, <field>.SetFocus() will properly move the mouse cursor to the field, while <field>.setfocus() will do nothing!

Additional Resources

The following list provides some additional information regarding the topics discussed in this chapter:

  • Microsoft CRM SDK: Available with Microsoft CRM and includes detailed information regarding the client-side integration options, as well as additional coding examples

  • DHTML overview: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp

  • DHTML object reference: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects.asp

  • JScript User's Guide: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/.asp

  • Regular expressions: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsreconintroductiontoregularexpressions.asp




Working with Microsoft Dynamics CRM 3.0
Working with Microsoft Dynamics(TM) CRM 3.0
ISBN: 0735622590
EAN: 2147483647
Year: 2006
Pages: 120

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net