Script Index
Below is an overview of handy JavaScript functions that we frequently use in our MS CRM implementations. These functions are developed “AS IS” and you can use them at own risk. CRM XPG will not officially give support on these functions. Nevertheless, we would appreciate any feedback, enhancements or additions you might have so we can continuously update this script library.
Index
| Name | Description | |
| gMid() | : | Returns the substring from start to start+len |
| gInstr() | : | Returns the first location a substring within any string. (If the character is not found, -1 is returned.) |
| gLeft() | : | Returns everything left of a position in a string or word |
| gRight() | : | Returns everything right of a position in a string or word |
| gLen() | : | The number of characters in the string |
| gLTrim() | : | Remove leading blanks from a string (left) |
| gRTrim() | : | Remove trailing blanks from a string (right) |
| gTrim() | : | Remove both trailing and leading blanks from our string. Dependencies: gLTrim() and gRTrim() |
| gLeftString() | : | Returns everything Left of a string or word, excl. the search string |
| gMiddleString() | : | Returns everything between two strings / words, reading from left to right |
| gRightString() | : | Returns everything Right of a string or word, excluding the search string or word |
| gRightStringIncl() | : | Returns everything Right of a string or word, including the search string or word |
| gReplaceString() | : | Function to replace any string (for one occurance) |
| gReplaceStringLoop() | : | Function to replace any string (for all occurances) |
| gReplaceSingleQuote() | : | Replace single quotes with " |
| gReplaceSpecialChars() | : | This function is used to replace special chars |
| gNullToString() | : | Replace Null and return empty string |
| gNullToZero() | : | Replace Null and return 0 (zero) |
| gClearOptionList() | : | Function to clear an optionlist |
| gListRemoveOption() | : | Remove an option of an optionlist |
| gListRenameOption() | : | Rename an option of an optionlist |
| gHideMenuItem() | : | Hide a menu item in the Navigation Pane based on the menuID |
| gHideMenuItemByTitle() | : | Hide a menu item in the Navigation Pane based on the title. |
| gShowMenuItem() | : | Show a menu item in the Navigation Pane based on the menuID |
| gAssociatedView() | : | Load and refresh a one-to-many or many-to-many grid in MS CRM |
| gLoad_iFrame() | : | Load an associated view in an iFrame for both system and custom entities |
| gLoad_iFrameByURL() | : | Load any URL in an iFrame, not only sub-entities related directly to the active entity. E.g. show contracts of selected account on case form |
| gLoad_IFrameByFetch() | : | Load any FetchXML in iFrame |
| gFilterLookup() | : | Filter a lookup based on another lookup. Dependencies: gReplaceSpecialChars() |
| gFilterLookupValue() | : | Filter a lookup based on any value. Dependencies: gReplaceSpecialChars() |
| gGetValue() | : | Return any field (from any entity) via MS CRM webservices |
| gGetValues() | : | Return multiple fields (from any entity) via MS CRM webservices |
| gFetchValues() | : | Return multiple fields (from any entity) using fetchXml |
| gGetResultXML() | : | Function to build an xml query string, call the MS CRM webservice and return the requested field(s) |
| gGetActivityHistoryCount() | : | Display the number of activities (=Open or Scheduled) or history (=Completed or Cancelled) items for an entity in the navigation pane |
| gGetRelatedActivityHistoryCount() | : | Display the number of activities, including the Related “Regarding” Records for an account or contact in the navigation pane |
| gLookupGetValue() | : | Return a value, guid, entity name or entity code from lookup field |
| gLookupSetValue() | : | Set a default value in a lookup field |
| gLookupChangeDisplayValue() | : | Change the display value of any lookup field |
| gLookupDisplayNewButton() | : | Hide or show the New button in a lookup |
| gGenerateNumber() | : | Return a random generated number including a prefix (if necessary) |
| gDisableField() | : | Make any field readonly or disabled, depending of the field type |
| gDisableForm() | : | Disable the entire form, all fields |
| gIsDate() | : | Check if a value is a date |
| gCDate() | : | Check and / or convert a value to date. Dependencies: gIsDate() |
| gDateAdd() | : | Add time,days,weeks, months,etc to any date. Dependencies: gCDate() |
| gDateDiff() | : | Calculate and return the difference between two dates (in hours, days, months, etc) |
| gCalculateWorkdays() | : | Calculates working days between two dates, excludling holidays (if necessary) |
| gFilterPicklist() | : | Filter a picklist (dynamically) based on another picklist. Dependencies: gLeft(), gLen(), gClearOptionList() |
| gFilterPicklistByArray() | : | Filter a picklist (dynamically) based on an array of picklist values. |
| gUpdateRecord() | : | Update a record in any entity in JavaScript using the MS CRM webservices |
| gCreateRecord() | : | Create a record for any entity in JavaScript using the MS CRM webservices |
| gDeleteRecord() | : | Delete a record in any entity via JavaScript using the MS CRM webservices |
| gCopyRecord() | : | Copy one or more fields from any entity to a new form (Client-Side) |
| gCopyRecordAjax() | : | Copy one or more fields from any entity using AJAX |
| gToggleSection() | : | Expand or collapse a section on a Form |
| gRenameSection() | : | Rename a section on a form |
| gDisplaySection() | : | Show or hide a section on a form |
| gDisplayField() | : | Show or hide a field on a form |
| gDisplayTab() | : | Show or hide a tab on a form using the display label |
| gIsAuthorizedForRoles() | : | Check if user is has access based on specified security role or roles. Dependencies: gNullToString(), gIsArray() |
| gIsAuthorizedForTeams() | : | Check if user is member of specified team or teams. Dependencies: gNullToString(), gIsArray() |
| gIsArray() | : | Check if object is an array |
| gValueInArray() | : | Check whether a value is listed in a specified array |
| gIncludeJavaScript() | : | Load an external javascript file into memory |
| gRoundNumber() | : | Round any number to any number of decimals |
| gAddImageToLabel() | : | Dynamically add an image to a label e.g. required or recommended |
| gGetParentForm() | : | Get and return a reference to the parent form of a related entity |
| gHideAssociatedViewButtons() | : | Hide any buttons on an associated view, both in the NavPane and in a custom iFrame (e.g. Add existing … to the record) |
| gSetDefaultAssociatedViewFilter() | : | Set a default filter of any in associated view, both in NavPane or an iFrame e.g. show Active Contracts for selected account. Dependencies: gLeft() |
| gOverrideAssociatedViewButton() | : | Override or change a function of an associated view button to call a custom function. Dependencies: gLeft() |
| gRenameMenuItem() | : | Change the text or title of a menu item |
| gCreateColumnLabels() | : | Convert section name into multiple column labels (max. 4) |
| gAddNotification() | : | Adds a notification message on the top of the entity form using the same visual style as Microsoft CRM |
| gCountLeft() | : | Count the number of characters entered in a field and trucate it (if necessary) |
| gRefreshAssociatedViewIFrame() | : | Refresh only the grid of an associated view in an iFrame without having to reload the entire form. |
| gExecuteWorkflow() | : | Execute / launch a workflow via JavaScript |
| gWaitWorkflowExecution() | : | Wait for a workflow, started in JavaScript, to complete in order to notify user. Requires: gExecuteWorkflow() |
| gMultiSelectPicklist() | : | Create a checkbox style Multi-Select Picklist on a CRM form and / or save the selected items |
| gTextFieldButton() | : | Add a helper / lookup button to a text field |
| ConvertTextFieldToButton() | : | Converts a text field to a button |
| ConvertTextToPicklist() | : | Converts a text field to a picklist |
| gGetEntityList() | : | Query the metadata web service in JavaScript to retrieve all entities |
| gGetAttributeList() | : | Query the metadata web service in JavaScript to retrieve all attributes |
| gGetEntityProperty() | : | Query the metadata web service in JavaScript to retrieve the ObjectTypeCode or another property of an entity e.g. DisplayName. Requires: gQueryMetadataService() |
| gSetTooltips() | : | Retrieve and display the attribute’s description as a tooltip |
| displayTooltips() | : | Dynamically retrieve tooltips based on a custom entity, completely configurable by the customer |
| gGetSubsidiaries() | : | Returns all sub-accounts in an array (from the active account on down). Dependencies: gGetValue(). |
| gGetCloseOppInformation() | : | Retrieve data from Close Opportunity dialogue to validate if all close out fields are filled and stop the form from closing. |
| gResizeLabel() | : | Change width of a field label beyond 250 pixels |
| gChangeFormTitle() | : | Change both the form title (ms-crm-Form-Title) and document title |

