The blog post does an excellent job explaining Activity entity with SQL.
JAVASCRIPT REFERENCE
33. Refresh a Sub-Grid:
34. Change the default entity in the lookup window of a Customer or Regarding field:
Note: I am setting the customerid field’s lookup window to offer Contacts (entityid 2) by default (rather than Accounts). I have also hardcoded the GUID of the default view I wish displayed in the lookup window.
35. Pop an existing CRM record (new approach):
36. Pop an existing CRM record (old approach):
Note: this example pops an existing Case record. The GUID of the record has already been established and is stored in the variable IncidentId.
37. Pop a blank CRM form (new approach):
38. Pop a new CRM record with default values (new approach):
39. Pop a new CRM record with default values (old approach):
Note: this example pops the Case form from the Phone Call form, defaulting the Case’s CustomerID based on the Phone Call’s SenderID and defaulting the Case Title to “New Case”
40. Pop a Dialog from a ribbon button
Note: this example has the Dialog GUID and CRM Server URL hardcoded, which you should avoid. A simple function is included which centres the Dialog when launched.
41. Pop a URL from a ribbon button
Great info on the window parameters you can set here: http://javascript-array.com/scripts/window_open/
42. Pop the lookup window associated to a Lookup field:
43. Pop a Web Resource (new approach):
44. Using a SWITCH statement
45. Pop an Ok/Cancel Dialog
46. Retrieve a GUID via REST (default the Price List field)
In this example (intended for the Opportunity form’s Onload event) I execute a REST query to retrieve the GUID of the Price List named “Wholesale Price List”. I then execute the DefaultPriceList function to default the Price List field. As this uses REST your CRM form will need json2 and jquery libraries registered on the CRM form (I have these libraries in a solution file I import when needed):
Here is a little more info that will help you get your head around the general design of all this…
Depending upon what you want to do you will interact with one of the following:
Xrm.Page.data.entity.attributes – The data fields represented by fields on the form
Xrm.Page.ui.controls – The user interface controls on the form
Xrm.Page.ui.navigation.items – The navigation items on the form
Xrm.Utility – A container of helpful functions
When referring to fields or controls you must specify the name of the field and surround with quotes (and make sure you get the case right):
When referring to nav items you must specify the nav ID and surround it with quotes. To determine the nav ID:
– open the CRM form in IE
– hit F12 to activate IE’s developer tools (if it doesn’t appear, check for it under Task Manager and maximise it from there)
– in the developer tools window click the arrow to activate the “Select element by click” mode
– on the CRM form click the nav item (the dev tools window will take you to HTML definition of that element)
– just above there you will see the nav ID specified, look for id=”nav<something>”
When setting properties to true/false do not surround the true/false value with quotes.
Typically there are 2 steps to interacting with fields. First you get the field as an object. Then you interact with that object to get or set the property value you are interested in.
Here’s an excellent post that provides a comparison of CRM v4 syntax and CRM 2011:
And here’s a download containing similar code snippets but provisioned as installable Visual Studio code snippets (something I wasn’t aware of but think is pretty cool!).
Here’s another useful jscript list: http://andreaswijayablog.blogspot.com/2011/07/crm-2011-javascript-functions.html
JAVASCRIPT REFERENCE
17. Disable a field:
18. Force Submit the Save of a Disabled Field:
19. Show/Hide a field:
20. Show/Hide a field based on a Bit field
21. Show/Hide a nav item:
Note: you need to refer to the nav id of the link, use F12 developer tools in IE to determine this
22. Show/Hide a Section:
Note: Here I provide a function you can use. Below the function is a sample.
23. Show/Hide a Tab:
Note: Here I provide a function you can use. Below the function is a sample.
24. Save the form:
25. Save and close the form:
26. Close the form:
Note: the user will be prompted for confirmation if unsaved changes exist
27. Determine which fields on the form are dirty:
28. Determine the Form Type:
Note: Form type codes: Create (1), Update (2), Read Only (3), Disabled (4), Bulk Edit (6)
29. Get the GUID of the current record:
30. Get the GUID of the current user:
31. Get the Security Roles of the current user:
(returns an array of GUIDs, note: my example reveals the first value in the array only)
32. Determine the CRM server URL:
JAVASCRIPT REFERENCE
1. Get the GUID value of a lookup field:
Note: this example reads and pops the GUID of the primary contact on the Account form
2. Get the Text value of a lookup field:
Note: this example reads and pops the name of the primary contact on the Account form
3. Get the value of a text field:
Note: this example reads and pops the value of the Main Phone (telephone1) field on the Account form
4. Get the database value of an Option Set field:
Note: this example reads and pops the value of the Address Type (address1_addresstypecode) field on the Account form
5. Get the text value of an Option Set field:
Note: this example reads and pops the value of the Address Type (address1_addresstypecode) field on the Account form
6. Get the database value of a Bit field:
7. Get the value of a Date field:
returns a value like: Wed Nov 30 17:04:06 UTC+0800 2011
and reflects the users time zone set under personal options
8. Get the day, month and year parts from a Date field:
9. Set the value of a string field:
Note: this example sets the Account Name field on the Account Form to “ABC”
10. Set the value of an Option Set (pick list) field:
Note: this example sets the Address Type field on the Account Form to “Bill To”, which corresponds to a database value of “1”
11. Set a Date field / Default a Date field to Today:
12. Set a Date field to 7 days from now:
13. Set the Time portion of a Date Field:
14. Set the value of a Lookup field:
Note: here I am providing a reusable function…
Here’s an example of how to call the function (I retrieve the details of one lookup field and then call the above function to populate another lookup field):
15. Split a Full Name into First Name and Last Name fields:
16. Set the Requirement Level of a Field:
Note: this example sets the requirement level of the Address Type field on the Account form to Required.
Note: setRequiredLevel(“none”) would make the field optional again.