Microsoft KB Archive/860854

= &quot;This is an Unexpected Token. Expected NAME&quot; error message occurs when adding Jscript to a Picklist OnChange Event in Microsoft CRM =

Article ID: 860854

Article Last Modified on 8/5/2005

-

APPLIES TO

 Microsoft Business Solutions CRM Software Development Kit, when used with:  Microsoft CRM 1.2

 Microsoft Business Solutions CRM 1.0 

-



TechKnowledge Content
'''Issue

'''JScript has been added to the OnChange event of a picklist field in Microsoft Customer Relationship Management (Microsoft CRM). This is accomplished through the following steps:

1. Navigate to Settings | System Customization

2. Select the appropriate object and click Customize Form

3. Locate the desired picklist field and double click to open the properties window.

4. Choose the Events tab and click the edit button.

5. On the Event Details: OnChange window mark the Event enabled check box, add the script and any necessary field dependencies.

The customization was published in Deployment Manager and an IISReset performed. Now when opening the form that contains the picklist, e.g. the Opportunity form, an error is returned: &quot;This is an unexpected token. Expected 'NAME'.&quot;

'''Potential Cause

'''The JScript that was added to the picklist contains either a less than symbol (<) or it contains two ampersands (&&), as in the following examples:

Ampersand Example:

if (true && !false)

{

alert;

}

Less Than Example:

if (1 < 2)

{

alert;

}

'''

Resolution

'''Use the escape sequence to enter the character instead of the character itself. The use of the escape sequence is required because the JScript is stored in the XML form definition and without the escape sequence is interpreted as part of the XML structure.

Ampersand Example:

if (true &amp;&amp; !false)

{

alert;

}

Less Than Example:

if (1 &lt; 2)

{

alert;

}

'''Note

'''If the Event Details window is opened to edit the script, the escape sequence will now show as the character. If the character is not replaced by the escape sequence, then the error will be encountered again.

It is recommended that you write and modify the code in a separate text file and then paste it into the Event tab. This way you will always have a back up of your code. Also, Microsoft CRM does not preserve white space in your script. Therefore, this allows you to debug your code in an environment where you can see the structure of your script as well.

For more information on using OnChange Events, refer to the following Technical Article, Using OnChange Events to Customize the Data Entry Process, available on MSDN:

This article was TechKnowledge Document ID: 32064

Keywords: kbmbsjscript kbmbscustomization kbmbsmigrate KB860854

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.