Client Scripting
Client Scripting
NOTE
You can also use business rules, which provides a way for someone who does not know JavaScript and is not a developer, to
apply business process logic in a form. More information: Create business rules and recommendations to apply logic in a
form
Forms in Customer Engagement help display data to the user. A form in Customer Engagement can contain items
such as fields, a quick form, or a grid. An event occurs in Customer Engagement forms whenever:
A form loads
Data is changed in a field or an item within the form
Data is saved in a form
You can attach your JavaScript code to "react" to these events so that your code gets executed when the event
occurs on the form. You attach your JavaScript code (scripts) to these events by using a Script web resource in
Customer Engagement.
Customer Engagement provides you a rich set of client APIs to interact with form objects and events to control
what and when to display on a form.
NOTE
Some client APIs are deprecated in the current release of Dynamics 365 Customer Engagement. Ensure that you are aware of
these APIs as you write your client-side code for Customer Engagement. More information: Deprecated client APIs
Get Started
Events in forms and grids
Understand the Client API object model
Walkthrough: Write your first client script
Reference
Client API reference
Related topics
Web resources for Customer Engagement
Customize commands and the ribbon
Events in forms and grids in Customer Engagement
8/24/2018 • 2 minutes to read • Edit Online
IMPORTANT
The execution context is automatically passed as the first parameter to functions that are set using the code. More
information: Client API execution context
OBJECT DESCRIPTION
Related topics
Client API global context
Client API reference
Client API execution context
8/24/2018 • 2 minutes to read • Edit Online
Defining event handlers using code: The execution context is automatically passed as the first
parameter to functions set using code. For a list of methods that can be used to define event handlers in
code, see Add or remove functions to events using code.
The execution context object provides a number of methods to further work with the context. More
information: Execution context (Client API reference)
Related topics
Client API form context
Client API grid context
Form and grid context in ribbon actions
Client API form context
8/24/2018 • 4 minutes to read • Edit Online
IMPORTANT
Deprecated means that we intend to remove a feature or capability from a future major release of Dynamics 365; the
feature or capability will continue to work and is fully supported until it is officially removed.
Use of the [Link] object as a static access to the primary form context is still supported to maintain backward
compatibility with the existing scripts, and won’t be removed as soon as some other client API methods listed in the
Client API deprecation section. We recommend that you use the new formContext object instead of the [Link]
object in your code targeting version 9.0 or later where possible. Also, using the formContext object enables you to
create common event handlers that can operate either on a form or in an editable grid depending on where its called.
More information: getFormContext (Client API reference).
Getting the formContext object for JavaScript functions for ribbon actions is different from how you get it in form
scripting. More information: Form and grid context in ribbon actions.
function displayName()
{
var firstName = [Link]("firstname").getValue();
var lastName = [Link]("lastname").getValue();
[Link](firstName + " " + lastName);
}
Here is the updated script that uses the passed in execution context to retrieve the formContext object
instead of using the static [Link] object:
function displayName(executionContext)
{
var formContext = [Link](); // get formContext
data object
Provides access to the entity data and methods to manage the data in the form as well as in the business
process flow control. Contains the following objects:
OBJECT DESCRIPTION
It also provides an attributes collection for accessing non-entity bound control. See the Collections in the
formContext object model section later in this topic.
More information: [Link]
ui object
Provides methods to retrieve information about the user interface, in addition to collections for several sub
components of the form or grid. Contains the following objects:
OBJECT DESCRIPTION
OBJECT DESCRIPTION
COLLECTION DESCRIPTION
- [Link]: Because an
attribute may have more than one control on the form, this
collection provides access to each of them. This collection
will contain only one item unless multiple controls for the
attribute are added to the form.
[Link] When multiple forms are provided for an entity, you can
associate each form with security roles. When the security
roles associated with a user enable them to see more than
one form, the [Link]
collection provides access to each form definition available
to that user.
COLLECTION DESCRIPTION
[Link] Provides methods to access all the quick view controls and
its constituent controls on the Customer Enagagement
forms.
[Link] You can organize each form by using one or more tabs. This
collection provides access to each of these tabs.
[Link] You can organize each form tab by using one or more
sections. The tab sections collection provides access to
each of these sections.
Related topics
getFormContext method
getGlobalContext method
Execution context methods
Client API grid context
8/24/2018 • 2 minutes to read • Edit Online
function doSomething(executionContext) {
var formContext = [Link](); // get the form Context
var gridContext = [Link]("Contacts"); // get the grid context
Executing code on a grid event: Use the getFormContext method of the passed in execution context
object to directly return reference to the grid where the code is executed. The grid events include
OnChange, OnRecordSelect, and OnSave.
function doSomething(executionContext) {
var gridContext = [Link](); // get the grid context
For more information about working with methods and events available for grids and subgrids, see Grids and
subgrids.
NOTE
Getting the gridContext object for JavaScript functions for ribbon actions is different from how you get it in form scripting.
More information: Form and grid context in ribbon actions
Related topics
Client API form context
Client API execution context
Understand the Client API object model
Grids and subgrids
Client API Xrm object
8/24/2018 • 2 minutes to read • Edit Online
Here is the information about each of the namespaces in the Xrm object:
NAMESPACE DESCRIPTION
NOTE
[Link] is deprecated in the current release, and you should now use the new [Link]
method to get global context in your code targeting version 9.0 or later.
To access the global context information in a standalone HTML Web resource, you should include a reference to
[Link] in the web resource, and then use the GetGlobalContext function. More
information: GetGlobalContext function and [Link]
Related topics
Understand the Client API object model
Deprecated client APIs
Walkthrough: Write your first client script
8/24/2018 • 8 minutes to read • Edit Online
Objective
After completing this walkthrough, you will know how to use your JavaScript code in Customer Engagement,
which involves the following steps at a high level:
Write your JavaScript code to address a business issue
Upload your JavaScript code as a web resource in Customer Engagement
Associate the JavaScript functions in the web resource to different client-side events in Customer Engagement.
We will draw your attention to important facts during the walkthrough, and provide references to actual methods
as appropriate.
In this case, all the functions defined in this library can be used as Sdk.[functionName] .
Define global variables: The following section defines some global variables to be used in the script. Note
that you now don't need to go through the form context to get the user name. Context information is now
available globally using the [Link] method.
Code to execute on the OnLoad event: This section contains the code that will be executed when the
account form loads. For example, when you create a new account record or when you open an existing
account record.
The code uses the executionContext object to get the formContext object. When we attach our code with
the form event later, we will remember to select the option to pass the execution context to this function.
Next, we display a form level notification using the setFormNotification method. Next, we use the
setTimeOut method to delay the execution of the clearFormNotification method to clear the notification
after 5 seconds.
Code to execute on the OnChange event: Code in this sections will be associated with the Account
Name field in the account form so that it gets executed only when you change the account name value.
The code performs a case-insensitive search for "Contoso" in the account name, and if present,
automatically sets values for some fields in the account form.
// Automatically set some field values if the account name contains "Contoso"
var accountName = [Link]("name").getValue();
if ([Link]().search("contoso") != -1) {
[Link]("websiteurl").setValue("[Link]
[Link]("telephone1").setValue("425-555-0100");
[Link]("description").setValue("Website URL, Phone and Description set using
custom script.");
}
}
Code to execute on the OnSave event: The code in this section displays an alert dialog box using the
openAlertDialog method. This dialog box displays a message with the OK button; user can close the alert by
clicking OK.
Note that we are not passing in the execution context in this function as its not required to execute
[Link].* methods.
7. Choose Save to create the web resource containing your JavaScript code.
8. Choose Publish to publish your web resource.
This makes the web resource available to be selected under the Event Hadlers section in the Form Properties
dialog. Remember that we have three functions in our JavaScript code to be associated with approprite events in
the form.
1. Under the Event Handlers section, select Form as the control and OnLoad as the Event; click Add to add
an event handler for the OnLoad event.
2. In the Handler Properties dialog box:
Select the name of your web resource from the Library drop-down list, and specify
[Link] in the Function field. The function name is [Namespace].[Function] from your
JavaScript code.
Select Pass execution context as first parameter to pass in the execution context as a parameter
to this function. If you review the function definition in the code, we are passing an
executionContext object to our function definition, and selecting this option wires them up.
5. In the Handler Properties dialog box, select the name of your web resource from the Library drop-down
list, and specify [Link] in the Function field. We won't pass the execution context to the
function this time as the [Link] function code does not require it.
3. Edit the account name to add "Contoso" in the name and move to the next field by pressing TAB. This will
fire the OnChange event, and will automatically update the Phone, Website and Description fields with
the value specified in the code.
4. Finally clicking Save will fire the OnSave event, and will display the alert dialog with a message that you
configured in your code. Click OK to close the alert.
// Automatically set some field values if the account name contains "Contoso"
var accountName = [Link]("name").getValue();
if ([Link]().search("contoso") != -1) {
[Link]("websiteurl").setValue("[Link]
[Link]("telephone1").setValue("425-555-0100");
[Link]("description").setValue("Website URL, Phone and Description set using
custom script.");
}
}
Debugging tools for different browsers have similar capabilities. Once you have found your library, you can set a
break point and recreate the event that should cause your code to run.
Also look at the following blog post on our team blog site for more ideas on debugging your JavaScript code: Blog:
Debugging custom JavaScript code in CRM using browser developer tools.
function writeToConsole(message)
{
if (typeof console != 'undefined') {
[Link](message);
}
}
Unlike using the alert method, if you forget to remove any code that uses this function, people using the application
will not see your messages.
Best practices: Client scripting in Customer
Engagement
8/24/2018 • 3 minutes to read • Edit Online
function MyUniqueName_performMyAction()
{
// Code to perform your action.
}
Namespaced library names: Associate each of your functions with a JavaScript object to create a kind of
namespace to use when you call your functions as shown in the following example.
Then when you use your function you can specify the full name. The following example shows this.
[Link]();
If you call a function within another function you can use the this keyword as a shortcut to the object that
contains both functions. However, if your function is being used as an event handler, the this keyword will
refer to the object that the event is occurring on.
Avoid using unsupported methods
On the Internet, you can find many examples or suggestions that describe using unsupported methods. These may
include leveraging undocumented internal function for page controls. These methods may work but because they
are not supported, you can’t expect that they will continue to work in future versions of Microsoft Dynamics 365.
IMPORTANT
The Client API object model also contains the [Link] namespace, and use of the objects/methods in this namespace
isn’t supported. These objects, and any parts of the HTML Document Object Model (DOM), are subject to change without
notice. We recommend that you don’t use these functions or any script that depends on the DOM.
Also, while debugging, you may find methods and objects in the Client API object model that aren’t documented. Only
documented objects and methods are supported.
Attribute event
OnChange
Form events
OnLoad
OnSave
Process events
OnProcessStatusChange
OnStageChange
OnStageSelected
Tab event
TabStateChange
Related topics
Events in forms and grids
Attribute OnChange Event (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
Although the Status field supports the OnChange event, the field is read-only on the form so the event cannot occur
through user interaction. Another script could cause this event to occur by using the fireOnchange method on the field.
Related topics
addCustomFilter
Subgrid OnLoad Event (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
Related topics
Client API form context
forEach method for collections (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](delegate function(attribute, index))
Parameters
Delegate function with parameters for attribute and index. |
Related topics
Collections in Client API
get
getLength
get method for collections (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]([String][Number][delegate function(attribute, index)])
Parameters
PARAMETER RETURN VALUE RETURN TYPE
delegate function(attribute, index) Any objects that cause the delegate Array
function to return true.
Related topics
Collections in Client API
forEach
getLength
getLength method for collections (Client API
reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Return value
Type: Number
Description: Count of items in the collection.
Related topics
Collections in Client API
forEach
get
GetGlobalContext function and
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
Including a reference to [Link] does not make the Xrm object available in HTML web resources.
Therefore, scripts containing Xrm.* methods aren’t supported in HTML web resources. [Link].* will work if the
HTML web resource is loaded in a form container. However, for other places, such as loading an HTML web resource as part of
the SiteMap, [Link].* also won’t work.
GetGlobalContext function
The GetGlobalContext function returns the same context object as returned by the
[Link] method, which implies that the context object will have the same properties and
methods as available for [Link]. More information: [Link]
[Link]
You must include a reference to the [Link] page located at the root of the web resources
directory to be able to use the GetGlobalContext function.
If you are not using backslash characters in HTML web resource names to simulate a folder structure, you
can include this script by directly referring to it. For example:
<head>
<title>HTML Web Resource</title>
<script src="[Link]" type="text/javascript" ></script>
</head>
If you are using backslash characters in HTML web resource names to simulate a directory structure, you
must reflect this in your script element. The following example is for an HTML web resource named
sdk_/[Link] and a JavaScript web resource named sdk_/Scripts/[Link] with a CSS web
resource named sdk_/Styles/[Link].
<head>
<title>HTML Web Resource</title>
<script src="../[Link]" type="text/javascript" ></script>
NOTE
Using a relative path including the root WebResources folder, for example, /WebResources/[Link], is not
recommended because it can cause the page to lose organization context in a multi-tenant environment.
The [Link] page will include some global event handlers. These event handlers will cancel
the onselectstart, contextmenu, and ondragstart events.
Related topics
[Link]
Understand Client API object model
Web resources for Customer Engagement
Execution context (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
getDepth Returns a value that indicates the order in which this handler
is executed.
getEventSource Returns a reference to the object that the event occurred on.
Related topics
Client API execution context
Save event arguments
Understand Client API object model
getDepth (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Return value
Type: Number
Description: The order in which this handler is executed. The order begins with 0.
Related topics
Execution context
getEventArgs (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Return value
Type: Object
Description: See Save Event Arguments.
Related topics
Execution context
getEventSource (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Return value
Type: Object
Description: Returns the object from the Xrm object model that is the source of the event, not an HTML DOM
object. For example, in an OnChange event, this method returns the [Link] attribute object that
represents the changed attribute.
Related topics
Execution context
getFormContext (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Return value
Type: Object
Description: Returns a reference to the form or an item on the form such as editable grid depending on where the
method was called. This method enables you to create common event handlers that can operate either on a form or
an item on the form depending on where its called.
Example
The following sample code demonstrates how you can create a method that sets notification on a form field or
editable grid cell depending on where you registered the script (Field OnChange event or editable grid OnChange
event):
function commonEventHandler(executionContext) {
var formContext = [Link]();
var telephoneAttr = [Link]('telephone1');
var isNumberWithCountryCode = [Link]().substring(0,1) === '+';
if (!isNumberWithCountryCode) {
[Link]('Please include the country code beginning with ‘+’.',
'countryCodeNotification');
}
else {
[Link]('countryCodeNotification');
}
}
Related topics
Execution context
Form context
getSharedVariable (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](key)
Parameters
key
Type: String
Description: The name of the variable.
Return value
Type: Object
Description: The specific type depends on what the value object is.
Related topics
setSharedVariable
Execution context
setSharedVariable (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](key, value)
Parameters
key: String: The name of the variable
Value: Object. The values to set
Return value
Type: Object
Description: The specific type depends on what the value object is.
Related topics
getSharedVariable
Execution context
Save event arguments (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
getSaveMode Returns a value indicating how the save event was initiated by
the user.
isDefaultPrevented Returns a value indicating whether the save event has been
canceled because the preventDefault method was used in this
event hander or a previous event handler.
preventDefault Cancels the save operation, but all remaining handlers for the
event will still be executed.
Related topics
Client API execution context
Execution context methods
getSaveMode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().getSaveMode()
Return Value
Type: Number
Description: The following table describes the supported values returned to detect different ways entity records
may be saved by the user.
1 Save All
5 Deactivate All
6 Reactivate All
7 Send Email
15 Disqualify Lead
16 Qualify Lead
Remarks
This method is essential if you want to enable auto-save for most forms in an organization but disable it for specific
forms.
Example
The following code registered for the OnSave event with the execution context passed to it will prevent any saves
that initiate from an auto-save but allow all others. With auto-save enabled, navigating away is equivalent to Save
and Close. This code will prevent any saves that are initiated by the 30 second timer or when people navigate away
from a form with unsaved data.
function preventAutoSave(executionContext) {
var eventArgs = [Link]();
if ([Link]() == 70 || [Link]() == 2) {
[Link]();
}
}
To save a record the user must click the Save icon at the bottom of the form or a custom Save command needs to
be added to the command bar.
Related topics
isDefaultPrevented
preventDefault
isDefaultPrevented (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().isDefaultPrevented();
Return Value
Type: Boolean
Description: true if the save event has been canceled because the preventDefault method was used; false
otherwise.
Related topics
getSaveMode
preventDefault
preventDefault (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().preventDefault();
Related topics
getSaveMode
isDefaultPrevented
Attributes (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
getInitialValue
getOption
getOptions
getSelectedOption
getText
Number attribute type (decimal, double, integer, money)
The following methods are available only for the decimal, double, and integer attributes:
getMax
getMin
getPrecision
setPrecision
getText
Address 2 address2_composite
Address 1 address1_composite
Address 2 address2_composite
Address 1 address1_composite
Address 2 address2_composite
Address address1_composite
Although not explicitly added to the form in the form editor, each of the attributes that are part of the attribute are
available to the form. Although you can read the value of the composite value using getValue, you can’t use
setValue to change the value of the composite attribute directly; you must set one or more of the attributes
referenced by the composite attribute.
You can access the individual constituent controls displayed in the flyout by name. These controls use the following
naming convention: <composite control name>_compositionLinkControl_<constituent attribute name>.
To access just the address_line1 control in the address1_composite control, you would use:
[Link]("address1_composite_compositionLinkControl_address1_line1")
function showAddressDialog(executionContext) {
var address1_compositeValue;
var formContext = [Link]();
if ([Link]().[Link]() != "Mobile") {
address1_compositeValue = [Link]("address1_composite").getValue();
}
else {
var address1_line1 = [Link]("address1_line1").getValue();
var address1_line2 = [Link]("address1_line2").getValue();
var address1_line3 = [Link]("address1_line3").getValue();
var address1_city = [Link]("address1_city").getValue();
var address1_stateorprovince = [Link]("address1_stateorprovince").getValue();
var address1_postalcode = [Link]("address1_postalcode").getValue();
var address1_country = [Link]("address1_country").getValue();
address1_compositeValue = addressText;
}
[Link]({ text: address1_compositeValue });
[Link](address1_compositeValue);
}
Related topics
Attributes
addOnChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).addOnChange(myFunction)
Parameters
PARAMETER NAME TYPE DESCRIPTION
Related topics
removeOnChange
Attribute OnChange Event
Controls collection (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).fireOnChange()
Related topics
Attribute OnChange Event
getAttribute (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getAttributeType()
Return Value
This method will return one of the following string values:
boolean
datetime
decimal
double
integer
lookup
memo
money
multioptionset
optionset
string
getFormat (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getFormat()
Return Value
This method will return one of the following string values or "null":
date
datetime
duration
email
language
none
phone
text
textarea
tickersymbol
timezone
url
NOTE
This format information generally represents the format options of the application field. Format options for Boolean fields are
not provided.
The following table lists the format string values to expect for each type of attribute schema type and format option.
Syntax
[Link](arg).getInitialValue()
Return Value
Type: Number
Description: The initial value for the attribute.
getIsDirty (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getIsDirty()
Return Value
Type: Boolean.
Description: True if there are unsaved changes, otherwise false.
getIsPartyList (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getIsPartyList()
Return Value
Type: Boolean.
Description: True if the lookup attribute is a partylist, otherwise false.
getMax (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getMax()
Return Value
Type: Number.
Description: The maximum allowed value for the attribute.
getMaxLength (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getMaxLength()
Return Value
Type: Number.
Description: The maximum allowed length of a string for this attribute.
NOTE
The email form description attribute is a memo attribute, but it does not have a getMaxLength method.
getMin (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getMin()
Return Value
Type: Number.
Description: The minimum allowed value for the attribute.
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getName()
Return Value
Type: String.
Description: The logical name of the attribute.
Related topics
setSubmitMode (Client API reference)
getOption (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getOption(value)
Parameters
String (label of the option) or Number (enumeration value of the option).
Return Value
Type: Option object.
Description: The logical name of the attribute.
getOptions (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getOptions()
Return Value
Type: Array of option objects.
Description: The array of option objects representing valid options.
getParent (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getParent()
Return Value
Type: [Link] object.
Description: The parent object.
getPrecision (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getPrecision()
Return Value
Type: Number.
Description: The number of digits allowed to the right of the decimal point.
Related topics
setPrecision
getRequiredLevel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getRequiredLevel()
Return Value
Type: String.
Description: Returns one of the following values:
none
required
recommended
Related topic
setRequiredLevel (Client API reference)
getSelectedOption (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getSelectedOption()
Return Value
Type: Option object for optionset; array of option objects for multiselectoptionset.
Description: Returns the object with text and value properties.
Related topics
getInitialValue (Client API reference)
getOption (Client API reference)
getOptions (Client API reference)
getText (Client API reference)
getSubmitMode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getSubmitMode()
Return Value
Type: String.
Description: Returns one of the following values:
always
never
dirty
Related topic
setSubmitMode (Client API reference)
getText (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getText()
Return Value
Type: String.
Description: The text value of the selected option.
Related topics
getInitialValue (Client API reference)
getOption (Client API reference)
getOptions (Client API reference)
getSelectedOption (Client API reference)
getUserPrivilege (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getUserPrivilege()
Return Value
Type: Object.
Description: The object has three Boolean properties:
canRead
canUpdate
canCreate
getValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getValue()
Return Value
Type: Depends on the type of attaribute.
boolean Boolean
datetime Date
To get the string version of a date using the Microsoft
Dynamics 365 user’s locale preferences, use the format and
localeFormat methods. Other methods will format dates using
the operating system locale rather than the user’s Microsoft
Dynamics 365 locale preferences.
decimal Number
Double Number
integer Number
lookup Array
An array of lookup objects.
memo String
money Number
optionset Number
string String
Related topic
setValue (Client API reference)
isValid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).isValid();
Return Value
Type: Boolean.
Description: true if the attribute value is valid; false otherwise.
removeOnChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).removeOnChange(myFunction)
Parameters
PARAMETER NAME TYPE DESCRIPTION
Related topics
addOnChange
Attribute OnChange Event
setPrecision (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setPrecision(value);
Parameter
PARAMETER NAME TYPE DESCRIPTION
Related topics
getPrecision
setRequiredLevel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
IMPORTANT
Reducing the required level of an attribute can cause an error when the page is saved. If the attribute is required by the
server, an error will occur if there is no value for the attribute.
Syntax
[Link](arg).setRequiredLevel(requirementLevel)
Parameters
Type: String.
Description: Set the level to one of the following values:
none
required
recommended
Related topic
getRequiredLevel (Client API reference)
setSubmitMode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setSubmitMode(mode)
Parameters
Type: String.
Description: Set one of the following mode values:
always: The data is always sent with a save.
never: The data is never sent with a save. When this is used, the field(s) in the form for this attribute cannot be
edited.
dirty: Default behavior. The data is sent with the save when it has changed.
Remarks
Use this method to control when data for an attribute is submitted when a record is created or saved. For example,
you may have a field on the form which is only intended to control logic in the form. You are not interested in
capturing the data in it. You might set it so that the data is not saved. Or you may have a Plugin that depends on the
value always being included. You may want to set the attribute so that it will always be included.
Attributes that do not get updated after the initial save of the record, such as createdby, are set so that they will not
be submitted on save. To force an attribute value to be submitted whether it has changed or not, use this method
with the mode parameter set to “always”.
Related topic
getSubmitMode (Client API reference)
setValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setValue(value)
Parameters
Depends on the type of attribute.
boolean Boolean
datetime Date
decimal Number
double Number
Integer Number
memo String
money Number
ATTRIBUTE TYPE PARAMETERS TYPE
optionset Number
string String
memo String
money Number
String String
A String field with the email format requires that the string
represents a valid email address.
NOTE
Updating an attribute using setValue will not cause the OnChange event handlers to run. If you want the OnChange event
handlers to run you must use fireOnChange in addition to setValue.
When Microsoft Dynamics 365 for tablets is not connected to the server, setValue will not work.
You cannot set the value of composite attributes. More information: Write scripts for composite attributes.
Related topic
getValue (Client API reference)
Controls (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
The following methods for the Standard control are deprecated in this release: addOnKeyPress, fireOnKeyPress,
and removeOnKeyPress.
NOTE
When the knowledge base search control is added to the social pane, the name of the control will be
"searchwidgetcontrol_notescontrol". This name can’t be changed.
NOTE
Custom lookup filters are not supported in mobile offline. For information about the mobile offline feature, see Configure
mobile offline synchronization
Syntax
[Link](arg).addCustomFilter(filter, entityLogicaName)
Parameters
filter: String. The fetchXml filter element to apply. For example:
<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>
entityLogicalName: (Optional) String. If this is set, the filter only applies to that entity type. Otherwise, it
applies to all types of entities returned.
Remarks
This method can only be used in a function in an event handler for the Lookup Control PreSearch Event.
Example
The following code sample is for the Opportunity form Account (parentaccountid) lookup. When the
[Link] function is set in the form Onload event handler, the [Link]
function is added to the PreSearch event for that lookup. Remember to select the option to pass in the execution
context when setting the function in the form Onload event handler. The result is that only accounts with the
Category (accountcategorycode) value of Preferred Customer (1) will be returned.
// A namespace defined for SDK sample code
// You should define a unique namespace for your libraries
var Sdk = [Link] || {};
[Link] = function () {
addPreSearch
formContext
addCustomView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault)
Parameters
viewId: String. The string representation of a GUID for a view.
NOTE
This value is never saved and only needs to be unique among the other available views for the lookup. A string for a
non-valid GUID will work, for example “00000000-0000-0000-0000-000000000001”. It’s recommended that you use
a tool like [Link] to generate a valid GUID.
Remarks
This method doesn’t work with Owner lookups. Owner lookups are used to assign user-owned records.
addNotification (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).addNotification(notification);
Parameters
NAME TYPE REQUIRED DESCRIPTION
notification Object Yes The notification to add. The
object contains the following
attributes:
actions: (Optional)
Array of objects. A
collection of objects
with the following
attributes:
message:
(Optional)
String. The
body message
of the
notification to
be displayed
to the user.
Limit your
message to
100
characters for
optimal user
experience.
actions:
(Optional)
Array of
functions. The
corresponding
actions for the
message.
messages: Array of
Strings. The message
to display in the
notification. In the
current release, only
the first message
specified in this array
will be displayed. The
string that you
specify here appears
as bold text in the
notification, and is
typically used for title
or subject of the
notification. You
should limit your
message to 50
characters for optimal
user experience.
notificationLevel:
String. Defines the
type of notification.
Valid values are
ERROR or
RECOMMENDATION.
uniqueId: String. The
ID to use to clear this
notification when
using the
clearNotification
method.
Return Value
Type: Boolean
Description: Indicates whether the method succeeded.
Remarks
The addNotification method displays a notification with the messages you specified and two standard buttons:
Apply and Dismiss. Clicking Apply executes the action you define; clicking Dismiss closes the notification
message.
Example
The following sample code displays a notification on the Account Name field of the account form to set the
Ticker Symbol if the Account Name field contains "Microsoft", and the ticker symbol is not already set to
"MSFT". Clicking Apply in the notification will set the Ticker Symbol field to "MSFT".
function addTickerSymbolRecommendation(executionContext) {
var formContext = [Link]();
var myControl = [Link]('name');
var accountName = [Link]('name');
var tickerSymbol = [Link]('tickersymbol');
[Link] = [function () {
[Link]('MSFT');
[Link]('my_unique_id');
}];
[Link]({
messages: ['Set Ticker Symbol'],
notificationLevel: 'RECOMMENDATION',
uniqueId: 'my_unique_id',
actions: [actionCollection]
});
}
else
[Link]("Notification not set");
}
Related topics
clearNotification
setNotification
addOnPostSearch (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>";
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
PostSearch event
removeOnPostSearch
addOnResultOpened (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
OnResultOpened event
removeOnResultOpened
addOnSelection (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
OnSelection event
removeOnSelection
addOption (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).addOption(option, index);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
clearOptions
removeOption
addPreSearch (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).addPreSearch(myFunction)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
PreSearch event
removePreSearch
clearNotification (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).clearNotification(uniqueId);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean
Description: Indicates whether the method succeeded.
Related topics
addNotification
setNotification
clearOptions (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).clearOptions();
Related topics
addOption
removeOption
getAttribute (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getAttribute();
Return Value
Type: Object
Description: An attribute
Remarks
The constituent controls within a quick view control are included in the controls collection and these controls have
the getAttribute method. However, the attribute is not part of the attribute collection for the entity. While you can
retrieve the value for that attribute using getValue and even change the value using setValue, changes you make
will not be saved with the entity.
The following code shows using the value the contact mobilephone attribute when displayed on an account entity
form using a quick view control named contactQuickForm. This code hides the control when the value of the
attribute is null.
var quickViewMobilePhoneControl =
[Link]("contactQuickForm_contactQuickForm_contact_mobilephone");
if ([Link]().getValue() == null) {
[Link](false);
}
Syntax
[Link](arg);
Parameter
arg: Optional. You can access a ontrol on a form by passing an argument as either the name or the index value of
the control on a form. For example: [Link]("firstname") or [Link](0)
Return Value
Type: Object or Object collection.
Description: Object if you use the method with parameter; object collection if you use the method without any
parameters.
Related topics
formContext
getControlType (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
getControl(arg).getControlType();
Return Value:
Type: String
customcontrol: <namespace>.<name> A custom control for Dynamics 365 mobile clients (phones and
tablets)
Syntax
[Link](arg).getData();
Return Value
Type: String
Description: The data value passed to the Silverlight web resource.
Related topics
setData
getDefaultView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getDefaultView();
Return Value
Type: String
Description: ID of the default view.
Related topics
setDefaultView
getDefaultView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getDefaultView();
Return Value
Type: String
Description: ID of the default view.
Related topics
setDefaultView
getEntityTypes (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getEntityTypes();
Return Value
Type: Array of String
Description: The logical names of the entities allowed in this control.
Related topics
setEntityTypes
getInitialUrl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getInitialUrl();
Return Value
Type: String
Description: The initial URL.
Related topics
Controls
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getLabel();
Return Value
Type: String
Description: The label of the control.
Related topics
setLabel
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
The name assigned to a control is not determined until the form loads. Changes to the form may change the name assigned
to a given control.
Syntax
[Link](arg).getName();
Return Value
Type: String
Description: The name of the control.
Related topics
Controls
getObject (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getObject();
Return Value
Type: Object
Description: Object depends on the type of control:
An IFRAME returns the IFrame element from the Document Object Model (DOM ).
A Silverlight web resource will return the Object element from the DOM that represents the embedded
Silverlight plug-in.
getParent (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getParent();
Return Value
Type: [Link] section object
getSearchQuery (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
var searchQuery = [Link]();
Return Value
Type: String
Description: The text of the search query.
Related topics
setSearchQuery
getSelectedResults (Clienat APi Reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getShowTime();
Return Value
Type: Boolean
Description: true if shows the time portion of the date; false otherwise.
Related topics
setShowTime
getSrc (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getSrc();
Return Value
Type: String
Description: A URL representing the src property of the IFRAME or web resource.
Related topics
setSrc
getState (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getState();
Return Value
Type: Number
Description: Returns one of the following values:
VALUE STATE
1 Not Set
2 In progress
3 Warning
4 Violated
5 Success
6 Expired
7 Canceled
8 Paused
Related topics
Controls
getTotalResultCount (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
var searchCount = [Link]();
Return Value
Type: Number
Description: The count of the search result.
getValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getValue();
Return Value
Type: String
Description: The latest data value for a control.
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).getVisible();
Return Value
Type: Boolean.
Description: true if the control is visible; false otherwise.
Related topics
setVisible
openSearchResult (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
var openResultStatus = [Link](resultNumber, mode);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean
Description: Status of opening the specified search result. Returns 1 if successful; 0 if unsuccessful. The method
will return -1 if the specified resultNumber value is not present, or if the specified mode value is invalid.
refresh (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).refresh();
Related topics
Controls
removeOnPostSearch (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>";
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
PostSearch event
addOnPostSearch
removeOnResultOpened (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
OnResultOpened event
addOnResultOpened
removeOnSelection (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
[Link](myFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnSelection
removeOption (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).removeOption(value);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOption
clearOptions
removePreSearch (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).removePreSearch(myFunction)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
PreSearch event
addPreSearch
setData (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setData(string);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getData
setDefaultView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setDefaultView(viewId);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Example
This setDefaultViewSample function will set the account entity form primary contact lookup default view to the
My Active Contacts view.
function setDefaultViewSample(executionContext) {
var formContext = [Link]();
[Link]("primarycontactid").setDefaultView("{00000000-0000-0000-00AA-000010001003}");
}
Related topics
getDefaultView
setDisabled (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setDisabled(bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getDisabled
setEntityTypes (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setEntityTypes([entityLogicalNames]);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getEntityTypes
setFocus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setFocus();
setLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setLabel(label);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getLabel
setNotification (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setNotification(message,uniqueId);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean
Description: Indicates whether the method succeeded.
Remarks
Setting an error notification on a control will block the form from saving.
Related topics
addNotification
clearNotification
setSearchQuery (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var kbSearchControl = [Link]("<name>");
[Link](searchString);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
getSearchQuery
setShowTime (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setShowTime(bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
This method will show or hide the time component of a date control where the attribute uses the DateAndTime
format. This method will have no effect when the DateOnly format is used.
Related topics
getShowTime
setSrc (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setSrc(string);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getSrc
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg).setVisible(bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getVisible
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
NAME DESCRIPTION
Methods
NAME DESCRIPTION
getIsDirty Gets a boolean value indicating whether the form data has
been modified.
isValid Gets a boolean value indicating whether all of the form data is
valid. This includes the main entity and any unbound
attributes.
Related topics
[Link]
[Link]
addOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnLoad
Form data OnLoad event
getIsDirty (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Type
Type: Boolean
Description: true if the form data has changed; false otherwise.
Related topics
[Link]
formContext
isValid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Type
Type: Boolean
Description: true if all of the form data is valid; false otherwise.
Related topics
formContext
refresh (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](save).then(successCallback, errorCallback);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
formContext
removeOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnLoad
Form data OnLoad event
save (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](saveOptions).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
- saveMode: (Optional)
Number. Specify a value
indicating how the save
event was initiated. For a list
of supported values, see the
return value of the
getSaveMode method. Note
that setting the saveMode
does not actually take the
corresponding action; it is
just to provide information
to the OnSave event
handlers about the reason
for the save operation.
- useSchedulingEngine:
(Optional) Boolean. Indicate
whether to use the Book or
Reschedule messages
rather than the Create or
Update messages. This
option is only applicable
when used with
appointment, recurring
appointment, or service
activity records.
- message: String. A
localized error message.
Related topics
[Link]
formContext
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
NAME DESCRIPTION
Methods
NAME DESCRIPTION
getDataXml Returns a string representing the XML that will be sent to the
server when the record is saved. Only data in fields that have
changed are set to the server.
getEntityName Returns a string representing the logical name of the entity for
the record.
getId Returns a string representing the GUID value for the record.
getIsDirty Gets a boolean value indicating whether any fields in the form
have been modified.
getPrimaryAttributeValue Gets a string for the value of the primary attribute of the
entity.
isValid Gets a boolean value indicating whether all of the entity data
is valid.
save Saves the record synchronously with the options to close the
form or open a new form after the save is completed.
Related topics
Understand Xrm object model
Controls (Client API reference)
addOnSave (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnSave
Form OnSave event
getDataXml (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: In this example, the following three fields for an account record were updated: name, accountnumber,
telephone2.
"<account><name>Contoso</name><accountnumber>55555</accountnumber><telephone2>425 555-1234</telephone2>
</account>"
Remarks
This method does not work with Microsoft Dynamics 365 for tablets.
getEntityName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: The name of the entity.
getEntityReference (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Lookup object.
Description: The returned object has following three attributes:
entityType: String. Logical name of the entity record. For example, "account".
id: String. GUID value of the entity record.
name: (Optional) String. Name of the entity record.
getId (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: The GUID value for the record.
getIsDirty (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Type
Type: Boolean
Description: true if any fields in the form have been changed; false otherwise.
Related topics
[Link]
formContext
getPrimaryAttributeValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: The name of the entity.
Remarks
Each entity has one string attribute that is designated as the PrimaryNameAttribute. The value for this attribute is
used when links to the record are displayed.
isValid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Type
Type: Boolean
Description: true if all of the entity data is valid; false otherwise.
Related topics
formContext
removeOnSave (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnSave
Form OnSave event
save (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](saveOption);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Example
To open a new form after the save is completed:
[Link]("saveandnew");
Related topics
[Link]
formContext
[Link] (Client API reference)
8/24/2018 • 3 minutes to read • Edit Online
OnProcessStatusChange addOnProcessStatusChange
removeOnProcessStatusChange
OnStageChange addOnStageChange
removeOnStageChange
OnStageSelected addOnStageSelected
removeOnStageSelected
NAME DESCRIPTION
Process methods
A process contains the data for a business process flow. Use the methods to access properties of the process.
NAME DESCRIPTION
NAME DESCRIPTION
getProcessInstances Returns all the process instances for the entity record that the
calling user has access to.
Instance methods
A process instance contains the data for an instance of the business process flow. Use the methods to access
properties of the process instance.
NAME DESCRIPTION
NAME DESCRIPTION
Stage methods
A stage contains the data for a stage in a business process flow. Use the methods to access properties of the stage.
NAME DESCRIPTION
getEntityName Returns the logical name of the entity associated with the
stage.
Step methods
A step contains the data for a step in a stage in a business process flow. Use the methods to access properties of the
step.
NAME DESCRIPTION
Navigation methods
Use these methods to move to next and previous stages. Both these methods will cause the OnStageChange event
to occur.
NAME DESCRIPTION
NAME DESCRIPTION
Related topics
[Link] (Client API reference)
Understand Xrm object model
Controls (Client API reference)
addOnProcessStatusChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnProcessStatusChange
[Link]
addOnStageChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnStageChange
[Link]
addOnStageSelected (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnStageSelected
[Link]
removeOnProcessStatusChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnProcessStatusChange
[Link]
removeOnStageChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnStageChange
[Link]
removeOnStageSelected (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnStageSelected
[Link]
getActiveProcess (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var activeProcess = [Link]();
Return Value
Type: Process.
Description: The currently active process. See Process methods for the methods to access the properties of the
process returned.
Related topics
setActiveProcess)
[Link]
setActiveProcess (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](processId, callbackFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getActiveProcess
setActiveProcessInstance
[Link]
getEnabledProcesses (Client API reference)
8/24/2018 • 3 minutes to read • Edit Online
Syntax
[Link](callbackFunction(enabledProcesses));
Parameter
NAME TYPE REQUIRED DESCRIPTION
Example
The [Link] function in the example uses the [Link]
method to asynchronously retrieve information about business process flows that are enabled for the entity. The
sample passes an anonymous function as the first parameter. This function is executed asynchronously when the
data is returned and the data is passed as the parameter to the anonymous function.
The information about enabled business process flow is provided as a dictionary object where the Id of the process
is the name of the property and the name of the business process flow is the value of the property. The sample
code processes this information and sets the values in a global [Link] array to be accessed by
logic that executes later. The sample also loops through the values in the [Link] array, and uses
the [Link] function to write information about the retrieved business process flows to the console.
NOTE
The [Link] function in the sample JavaScript library must be set as the OnLoad event handler for a form, and the
Pass execution context as the first parameter check box must be selected in the Handler Properties dialog.
Also, this sample just illustrates the use of some of the methods in the [Link] API. It doesn’t represent
using this API to meet a business requirement; it’s only intended to demonstrate how the key property values can be
accessed in code.
//Any code that depends on the [Link] array needs to be initiated here
});
};
}).call(Sdk);
When you run this sample with the browser developer tools open, the following is an example of the output written
to the console for an entity with multiple business process flows enabled.
Enabled business processes flows retrieved and added to [Link] array.
These are the enabled business process flows for this entity:
id: 7994be68-899e-4a40-8d18-f5c3b6940188 name: Sample Lead Process
id: 919e14d1-6489-4852-abd0-a63a6ecaac5d name: Lead to Opportunity Sales Process
Related topics
setActiveProcessInstance
[Link]
getId (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var processId = [Link]();
Return Value
Type: String.
Description: Value represents the string representation of a GUID value.
Related topics
[Link]
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var processName = [Link]();
Return Value
Type: String.
Description: Name of the process.
Related topics
[Link]
getStages (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageCollection = [Link]();
Returns
Type: Collection.
Description: See Stage methods for the methods to access the properties of the stages returned.
Related topics
[Link]
isRendered (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var processRendered = [Link]();
Returns
Type: Boolean.
Description: true if the process is rendered; false otherwise.
Related topics
[Link]
getProcessInstances (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](callbackFunction(object));
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
setActiveProcessInstance
[Link]
setActiveProcessInstance (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](processInstanceId, callbackFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getProcessInstances
[Link]
getInstanceId (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Value represents the string representation of a GUID value.
Related topics
[Link]
getInstanceName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Pocess instance name.
Related topics
[Link]
getStatus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description:Returns one of the following values: active, aborted, or finished.
Related topics
[Link]
setStatus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](status, callbackFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Type: String.
Description:Returns one of the following values: active, aborted, or finished.
Related topics
[Link]
getActiveStage (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Stage.
Description: The currently active stage. See Stage methods for the methods to access the properties of the stage
returned.
Related topics
setActiveStage)
getSelectedStage (Client API reference)
[Link]
setActiveStage (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](stageId, callbackFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
VALUE REASO N
success The
operation
succeeded.
invalid There are
three
reasons
why this
value may
be
returned:
The
sta
geI
d
par
am
ete
r is
a
non
-
exis
tent
sta
ge
ID
val
ue.
The
acti
ve
sta
ge
isn’
t
the
sel
ect
ed
sta
ge.
The
rec
ord
has
n’t
bee
n
sav
ed
yet.
Related topics
getActiveStage
[Link]
getActivePath (Client API reference)
8/24/2018 • 3 minutes to read • Edit Online
Syntax
var stageCollection = [Link]();
Return Value
Type: Collection.
Description: A collection of all completed stages, the currently active stage, and the predicted set of future stages
based on satisfied conditions in the branching rule. This may be a subset of the stages returned with
[Link] because it will only include those stages which represent a valid
transition from the current stage based on branching that has occurred in the process.
Example
The [Link] function uses the [Link] method to retrieve a
collection of stages. Then, the sample code uses the forEach method of the collection to loop through each stage.
The code then writes key properties of the stage to the console using the [Link] function defined in
this library. The code then accesses a collection of steps for each stage using the getSteps method. Finally, the
sample uses the forEach method of the steps collection to access each step and write key properties of the step to
the console.
NOTE
The [Link] function in the sample JavaScript library must be set as the OnLoad event handler for a form, and the
Pass execution context as the first parameter check box must be selected in the Handler Properties dialog.
Also, this sample just illustrates the use of some of the methods in the [Link] API. It doesn’t represent
using this API to meet a business requirement; it’s only intended to demonstrate how the key property values can be
accessed in code.
// A namespace defined for SDK sample code
// You should define a unique namespace for your libraries
var Sdk = [Link] || {};
(function () {
When the sample runs in the browser, you can use the developer tools of the browser to view the text written to the
console. For example, when this sample is run in the Opportunity entity form with the Opportunity Sales Process,
the following is written to the console:
Stage Index: 0
Entity: opportunity
StageId: 6b9ce798-221a-4260-90b2-2a95ed51a5bc
Status: active
Step Name: Identify Contact
Step Attribute: parentcontactid
Step Required: false
---------------------------------------
Step Name: Identify Account
Step Attribute: parentaccountid
Step Required: false
---------------------------------------
Step Name: Purchase Timeframe
Step Attribute: purchasetimeframe
Step Required: false
---------------------------------------
Step Name: Estimated Budget
Step Attribute: budgetamount
Step Required: false
---------------------------------------
Step Name: Purchase Process
Step Attribute: purchaseprocess
Step Required: false
---------------------------------------
Step Name: Identify Decision Maker
Step Attribute: decisionmaker
Step Required: false
Step Required: false
---------------------------------------
Step Name: Capture Summary
Step Attribute: description
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 1
Entity: opportunity
StageId: 650e06b4-789b-46c1-822b-0da76bedb1ed
Status: inactive
Step Name: Customer Need
Step Attribute: customerneed
Step Required: false
---------------------------------------
Step Name: Proposed Solution
Step Attribute: proposedsolution
Step Required: false
---------------------------------------
Step Name: Identify Stakeholders
Step Attribute: identifycustomercontacts
Step Required: false
---------------------------------------
Step Name: Identify Competitors
Step Attribute: identifycompetitors
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 2
Entity: opportunity
StageId: d3ca8878-8d7b-47b9-852d-fcd838790cfd
Status: inactive
Step Name: Identify Sales Team
Step Attribute: identifypursuitteam
Step Required: false
---------------------------------------
Step Name: Develop Proposal
Step Attribute: developproposal
Step Required: false
---------------------------------------
Step Name: Complete Internal Review
Step Attribute: completeinternalreview
Step Required: false
---------------------------------------
Step Name: Present Proposal
Step Attribute: presentproposal
Step Required: false
---------------------------------------
---------------------------------------
Stage Index: 3
Entity: opportunity
StageId: bb7e830a-61bd-441b-b1fd-6bb104ffa027
Status: inactive
Step Name: Complete Final Proposal
Step Attribute: completefinalproposal
Step Required: false
---------------------------------------
Step Name: Present Final Proposal
Step Attribute: presentfinalproposal
Step Required: false
---------------------------------------
Step Name: Confirm Decision Date
Step Attribute: finaldecisiondate
Step Required: false
---------------------------------------
Step Name: Send Thank You
Step Attribute: sendthankyounote
Step Required: false
---------------------------------------
Step Name: File De-brief
Step Name: File De-brief
Step Attribute: filedebrief
Step Required: false
---------------------------------------
---------------------------------------
Related topics
[Link]
getSelectedStage (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Stage.
Description: The currently selected stage. See Stage methods for the methods to access the properties of the stage
returned.
Related topics
getActiveStage (Client API reference)
[Link]
getCategory (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageCategoryNumber = [Link]().getValue();
Return Value
Type: Number.
Description: Here is the list of possible values.
VALUE DESCRIPTION
0 Qualify
1 Develop
2 Propose
3 Close
4 Identify
5 Research
6 Resolve
Related topics
[Link]
getEntityName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageEntityName = [Link]();
Return Value
Type: String.
Description: Logical name of the entity associated with the stage.
Related topics
[Link]
getId (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageId = [Link]();
Returns
Type: String.
Description: Unique identifier of the stage in the GUID format.
Related topics
[Link]
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageName = [Link]();
Return Value
Type: String.
Description: Name of the stage.
Related topics
[Link]
getNavigationBehavior (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
This method is available only for Unified Interface.
Syntax
[Link]().allowCreateNew = function () {
return true|false;
}
Returns
Type: Object
Description: An object with the allowCreateNew property that lets you define whether the Create button will be
available in a stage so that user can create an instance of entityB from the entityA form in a cross-entity business
process flow navigation scenario.
For example, here is the Create button in the Develop stage of the AccountToContactProcess sample business
process flow that lets you create a Contact record from the Account form.
The allowCreateNew property will return undefined for business process flow records that do not implement
cross-entity navigation.
Example
The following sample code shows how you can hide or display the Create button for an active stage of a business
process flow depending on its name.
function sampleFunction(executionContext) {
var formContext = [Link]();
[Link]().allowCreateNew = function () {
if ([Link]() === 'Test Process') {
return false; // Create button is not available
}
else {
return true; // Create button is available
}
}
}
Related topics
[Link]
getStatus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stageStatus = [Link]();
Returns
Type: String.
Description: This method will return either active or inactive.
Related topics
[Link]
getSteps (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stepsCollection = [Link]();
Return Value
Type: Array.
Description: See Step methods for methods to access the property values of the step.
Related topics
[Link]
getAttribute (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stepAttributeName = [Link]();
Returns
Type: String.
Description: Some steps don’t contain an attribute value.
Related topics
[Link]
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stepName = [Link]();
Return Value
Type: String.
Description: Name of the step.
Related topics
[Link]
getProgress (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stepProgress = [Link]();
Return Value
Type: Number.
Description: Returns one of the following values:
VALUE DESCRIPTION
0 None
1 Processing
2 Completed
3 Failure
4 Invalid
Remarks
This method is supported only for the action steps; not for the data steps. Action steps are buttons on the business
process stages that users can click to trigger an on-demand workflow or action. Action step is a preview feature
introduced in the Dynamics 365 (online), version 9.0 release. More information: See the Business Process Flow
automation with Action Steps section in Blog: New automation and visualization features for Business Process
Flows (public preview )
Related topics
setProgress
[Link]
isRequired (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var stepIsRequired = [Link]();
Returns
Type: Boolean.
Description: true if the step is marked as required in the Business Process Flow editor; false otherwise.
Related topics
[Link]
setProgress (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](stepProgress,message);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String.
Description: Returns "invalid" or "success" depending on whether the step progress was updated.
Remarks
This method is supported only for the action steps. Action steps are buttons on the business process stages that
users can click to trigger an on-demand workflow or action. Action step is a preview feature introduced in the
Dynamics 365 (online), version 9.0 release. More information: See the Business Process Flow automation with
Action Steps section in Blog: New automation and visualization features for Business Process Flows (public
preview ).
Related topics
getProgress
[Link]
moveNext (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](callbackFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
callbackFunction Function No A function to call when the
operation is complete. This
callback function is passed
one of the following string
values to indicate the status
of the operation:
VALUE REASO N
success The
operation
succeeded.
invalid The
operation
failed
because
the
selected
stage isn’t
the same
as the
active
stage.
IMPORTANT
This method can only be used when the selected stage and the active stage are the same. When your code is initiated from
the OnStageChange event, the current stage will be selected. When your code is initiated from the OnStageSelected event,
you should use the getActiveStage method to verify that the selected stage is also the active stage. For any other form event,
it isn’t possible to determine which stage is currently selected. For best results, this method should only be used in code that
is called in functions initiated by the OnStageChange and OnStageSelected events.
Remarks
This methods will cause the OnStageChange event to occur.
Related topics
movePrevious
[Link]
movePrevious (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](callbackFunction);
Parameters
NAME TYPE REQUIRED DESCRIPTION
callbackFunction Function No A function to call when the
operation is complete. This
callback function is passed
one of the following string
values to indicate the status
of the operation:
VALUE REASO N
success The
operation
succeeded.
crossEntity The
previous
stage is
for a
different
entity.
invalid The
operation
failed
because
the
selected
stage isn’t
the same
as the
active
stage.
IMPORTANT
This method can only be used when the selected stage and the active stage are the same. When your code is initiated from
the OnStageChange event, the current stage will be selected. When your code is initiated from the OnStageSelected event,
you should use the getActiveStage method to verify that the selected stage is also the active stage. For any other form event,
it isn’t possible to determine which stage is currently selected. For best results, this method should only be used in code that
is called in functions initiated by the OnStageChange and OnStageSelected events.
Remarks
This methods will cause the OnStageChange event to occur.
Related topics
moveNext
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
NAME DESCRIPTION
Controls Collection of all the controls on the page. See Collections for
information about the collections and Controls for information
about the control objects in the collection.
quickForms A collection of all the quick view controls on a form using the
new form rendering engine (also called "turbo forms").
More information: [Link] quickForms
NAME DESCRIPTION
Methods
NAME DESCRIPTION
Related topics
formContext
addOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
removeOnLoad
Form OnLoad event
[Link]
formContext
clearFormNotification (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](uniqueId)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean
Description: true if the method succeeded, false otherwise.
Related topics
setFormNotification
[Link]
formContext
close (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Remarks
The HTML [Link] method is suppressed. To close a form window, you must use this method. If there are
any unsaved changes in the form, the user will be prompted whether they want to save their changes before the
window closes.
For Microsoft Dynamics 365 for tablets, this method mimics the behavior of the back navigation button.
Related topics
[Link]
formContext
getFormType (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Number
Description: Form type. Returns one of the following values
0 Undefined
1 Create
2 Update
3 Read Only
4 Disabled
6 Bulk Edit
NOTE
Quick Create forms return 1.
Related topics
[Link]
formContext
getViewPortHeight (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Number
Description: The viewport height in pixels.
Related topics
getViewPortWidth
[Link]
formContext
getViewPortWidth (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Number
Description: The viewport width in pixels.
Related topics
getViewPortHeight
[Link]
formContext
refreshRibbon (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](refreshAll);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
This function is typically used when a ribbon (RibbonDiffXml) depends on a value in the form. After your code
changes a value that is used by a rule, use this method to force the ribbon to re-evaluate the data in the form so
that the rule can be applied.
Related topics
[Link]
formContext
removeOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction)
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
addOnLoad
Form data OnLoad event
[Link]
formContext
setFormEntityName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
formContext
setFormNotification (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](message, level, uniqueId);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean
Description: true if the method succeeded; false otherwise.
Related topics
clearFormNotification
[Link]
formContext
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
This collection isn't available for Dynamics 365 mobile clients (phones and tablets).
[Link] method: Returns a reference to the form currently being shown. When only
one form is available this method will return null. Example:
formItem = [Link]();
NAME DECRIPTION
Syntax
[Link]();
Return Value
Type: String.
Description: ID of the form.
Related topics
[Link]
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Label of the form.
Related topics
[Link]
navigate (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Related topics
[Link]
[Link] item (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
These methods do not work with Microsoft Dynamics 365 for tablets.
Syntax
[Link]();
Return Value
Type: String.
Description: Name of the item.
Related topics
[Link]
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Label of the item.
Related topics
setLabel
[Link]
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if the item is visible; false otherwise..
Related topics
setVisible
[Link]
setFocus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Related topics
[Link]
setLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](label);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getLabel
[Link]
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getVisible
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NAME DESCRIPTION
getDisplayState Retrieves the display state for the business process control.
Syntax
[Link]();
Return Value
Type: String.
Description: Returns "expanded" or "collapsed" on the web client; returns "expanded", "collapsed", or "floating" on
Unified Interface.
Related topics
setDisplayState
[Link]
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if the control is visible; false otherwise.
Related topics
setVisible
[Link]
reflow (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](updateUI, parentStage, nextStage);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
setDisplayState (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](state);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getDisplayState
[Link]
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getVisible
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
getVisible Returns a value that indicates whether the quick view control is
currently visible.
isLoaded Returns whether the data binding for the constituent controls
in a quick view control is complete.
Syntax
[Link](arg);
Parameter
arg: Optional. You can access a single control in the constituent controls collection by passing an argument as
either the name or the index value of the constituent control in a quick view control. For example:
[Link]("firstname") or [Link](0)
Return Value
Type: Object or Object collection.
Description: Object if you use the method with parameter; object collection if you use the method without any
parameters.
Remarks
After you have retrieved a constituent control in a quick view control, you can use any of the methods supported
for a control in Customer Engagement on the constituent control that does not alter the constituent control data.
This is because constituent controls in a quick view control are read only. For example, you can use:
[Link](0).getAttribute()
For more information about methods supported for a control, see Controls.
IMPORTANT
The getAttribute or any data related methods on a constituent control might not work on the main form OnLoad event
because the quick view form that its bound to might not have loaded completely when the main form has loaded. You must
use the isLoaded method for the quick view control instance to help you determine if the bounded quick view form has
loaded completely.
Also, the way you retrieve constituent controls in a quick view control on forms using the new form rendering engine is
different from the legacy forms. So, if you are using legacy forms and have code targeting constituent controls in a quick view
control, you must update your code when you decide to use the new form rendering engine.
Related topics
[Link]
getControlType (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: For a quick view control, the method returns "quickform".
For a constituent control in a quick view control, the method returns the actual category of the control. For more
information about possible return values, see getControlType..
Related topics
[Link]
getDisabled (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if disabled; false otherwise.
Related topics
[Link]
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Label of the quick view control.
Related topics
setLabel
[Link]
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: The name of the quick view control.
Related topics
[Link]
getParent (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: [Link]
Related topics
[Link]
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
If the containing section or tab for this control isn’t visible, this method can still return true. To make certain that the control
is actually visible; you need to also check the visibility of the containing elements.
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if the control is visible; false otherwise.
Related topics
setVisible
[Link]
isLoaded (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true is the data binding for a constituent control is complete; false otherwise.
Remarks
The data binding for the constituent controls in a quick view control may not be complete during the main form
OnLoad event because the quick view form that the control is bound to may not have loaded completely. As a
result, using the getAttribute or any data-related methods on a constituent control might not work. The isLoaded
method for the quick view control helps determine the data binding status for constituent controls in a quick view
control.
Example
The following sample code demonstrates how you can use the isLoaded method to check the binding status, and
then retrieve the value of the attribute that a constituent control in a quick view control is bound to.
function getAttributeValue(executionContext) {
var formContext = [Link]();
var quickViewControl = [Link]("<QuickViewControlName>");
if (quickViewControl != undefined) {
if ([Link]()) {
// Access the value of the attribute bound to the constituent control
var myValue = [Link](0).getAttribute().getValue();
[Link](myValue);
return;
}
else {
// Wait for some time and check again
setTimeout(getAttributeValue, 10);
}
}
else {
[Link]("No data to display in the quick view control.");
return;
}
}
Related topics
[Link]
refresh (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link];
Related topics
[Link]
setDisabled (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getDisabled
[Link]
setFocus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Related topics
[Link]
setLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](label);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getLabel
[Link]
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getVisible
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
Sections: The sections collection provides access to sections within the tab. See Collections (Client API
reference) for information about methods to access the sections in the collection. See [Link] section for
information about the properties and methods of the section objects in the collection.
Methods
NAME DESCRIPTION
Related topics
[Link]
formContext
addTabStateChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
formContext
addTabStateChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
formContext
getDisplayState (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String.
Description: Returns "expanded" or "collapsed".
Related topics
setDisplayState
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The label of the tab.
Related topics
setLabel
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: Name of the tab.
getParent (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: [Link] object
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if the tab is visible; false otherwise.
Related topics
setVisible
removeTabStateChange (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
formContext
setDisplayState (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](state);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getDisplayState
setFocus (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Related topics
[Link]
setLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](label);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getLabel
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
Another way to hide a tab is to hide all the sections within it. If all the sections within a tab are not visible, the tab
will not be visible.
Related topics
getVisible
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
Controls: The section controls collection provides access to the controls within a section. See Collections (Client
API reference) for information about the methods exposed by collections. See Controls (Client API reference)
for information about the properties and methods exposed by the objects in this collection.
Methods
NAME DESCRIPTION
Related topics
[Link]
formContext
getLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The label of the section.
Related topics
setLabel
getName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: Name of the section.
Related topics
Controls
getParent (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: [Link] tab object
getVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean.
Description: true if the section is visible; false otherwise.
Related topics
setVisible
setLabel (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](label);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getLabel
setVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](bool);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Related topics
getVisible
Grids and subgrids in Customer Engagement (Client
API reference)
8/24/2018 • 2 minutes to read • Edit Online
Types of grids
There are two types of grids in Customer Engagement:
Read-only grids: Display data in a tabular format. To edit the data displayed in a read-only grid, you have to
click the record in the grid to open the form, edit the data, and then save.
Editable grids: In addition to displaying data in a tabular format, provides rich inline editing capabilities on
web and mobile clients including the ability to group, sort, and filter data within the same grid so that you do
not have to switch records or views. The editable grid is a custom control, and is supported in the main grid
and subgrids on a form in the web client and in dashboards and on form grids on the mobile clients. Although
the editable grid control provides editing capability, it honors the read-only grid metadata and field-level
security settings.
Events
NAME DESCRIPTION APPLICABLE FOR
Subgrid OnLoad Event Occurs every time the subgrid Read-only grid
refreshes. This includes when users sort
values in subgrid by clicking the
column headings.
NOTE
You can register for the OnChange, OnRecordSelect, and OnSave events using the Events tab of the Dynamics 365
Customer Engagement page that is used to enable editable grids for an entity or a read-only grid.
Methods
NAME DESCRIPTION AVAILABLE FOR
GridControl Provides methods to work with the Read-only and editable grids
grid or subgrid control.
GridRow Provides methods to work with rows or Read-only and editable grids
selected rows in the grid.
GridRowData Provides methods to work with rows or Read-only and editable grids
selected rows in the grid.
GridEntity Provides methods to access data about Read-only and editable grids
the specific records in the rows.
Related topics
Client API grid context
Use editable grids in Customer Engagement
Client API Reference for Customer Engagement
Developer Guide for Dynamics 365 Customer Engagement
GridControl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Methods
NAME DESCRIPTION AVAILABLE FOR
getEntityName Gets the logical name of the entity data Read-only and editable grids
displayed in the grid.
getFetchXml Gets the FetchXML query that Read-only and editable grids
represents the current data, including
filtered and sorted data, in the grid
control.
getGrid Get access to the Grid available in the Read-only and editable grids
GridControl (gridContext).
getGridType Gets the grid type (grid or subgrid). Read-only and editable grids
getRelationship Gets information about the relationship Read-only and editable grids
used to filter the subgrid.
getUrl Gets the URL of the current grid control. Read-only and editable grids
openRelatedGrid Displays the the associated grid for the Read-only and editable grids
grid.
refreshRibbon Refreshes the ribbon rules for the grid Read-only and editable grids
control.
Related topics
Grid
Grids and subgrids in Customer Engagement
addOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
To get the gridContext , see Getting the grid context.
Example
Add the myContactsGridOnloadFunction function to the Contacts subgrid OnLoad event.
function myFunction(executionContext) {
var formContext = [Link](); // get the form context
var gridContext = [Link]("Contacts");// get the grid context
var myContactsGridOnloadFunction = function () { [Link]("Contacts Subgrid OnLoad event occurred") };
[Link](myContactsGridOnloadFunction);
}
Related topics
removeOnLoad
getEntityName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The logical name of the entity data displayed in the grid.
Remarks
To get the gridContext , see Getting the grid context.
getFetchXml (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var result = [Link]();
Return Value
Type: String
Description: The FetchXML query.
Remarks
To get the gridContext , see Getting the grid context
Example
The following example displays the retrieved Fetch XNL of the Contacts subgrid in the Console:
function myFunction(executionContext) {
var formContext = [Link](); // get the form context
var gridContext = [Link]("Contacts"); // get the grid context
var retrieveFetchXML = function () {
var result = [Link]();
[Link](result)
};
[Link](retrieveFetchXML);
}
getGrid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var grid = [Link]();
Return Value
Type: Grid
Description: The Grid object.
Remarks
To get the gridContext , see Getting the grid context.
getGridType (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var gridType = [Link]();
Return Value
Type: Number
Description: Returns one of the following values:
VALUE DESCRIPTION
1 HomePageGrid
2 Subgrid
Remarks
To get the gridContext , see Getting the grid context.
getRelationship (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Object.
Description: A relationship object with the following attributes:
attributeName: String. Name of the attribute.
name: String. Name of the relationship.
navigationPropertyName: String. Name of the navigation property for this relationship.
relationshipType: Number. Returns one of the following values to indicate the relationship type:
0: OneToMany
1: ManyToMany
roleType: Number. Returns one of the following values to indicate the role type of relationship:
1: Referencing
2: AssociationEntity
Remarks
To get the gridContext , see Getting the grid context.
Related topics
openRelatedGrid
Customize entity relationship metadata
getUrl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](client);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: The Url of the current grid control.
Remarks
To get the gridContext , see Getting the grid context.
getViewSelector (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: ViewSelector
Description: The ViewSelector object.
Remarks
To get the gridContext , see Getting the grid context.
openRelatedGrid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Remarks
To get the gridContext , see Getting the grid context.
Related topics
getRelationship
Customize entity relationship metadata
refresh (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Remarks
To get the gridContext , see Getting the grid context.
refreshRibbon (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Remarks
To get the gridContext , see Getting the grid context.
removeOnLoad (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](myFunction);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
To get the gridContext , see Getting the grid context.
Related topics
addOnLoad
Grid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Methods
NAME DESCRIPTION AVAILABLE FOR
getTotalRecordCount Returns the total number of records Read-only and editable grids
that match the filter criteria of the view,
not limited by the number visible in a
single page.
Related topics
GridRow
Grids and subgrids in Customer Engagement
getRows (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var allRows = [Link]().getRows();
Return Value
Type: Collection
Description: A collection of rows in the grid.
Remarks
To get the gridContext , see Getting the grid context.
See Collections (Client API reference) for information on the methods available to access data in a collection.
getSelectedRows (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var allSelectedRows = [Link]().getSelectedRows();
Return Value
Type: Collection
Description: A collection of selected rows in the grid.
Remarks
To get the gridContext , see Getting the grid context.
See Collections (Client API reference) for information on the methods available to access data in a collection.
getTotalRecordCount (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var filteredRecordCount = [Link]().getTotalRecordCount();
Return Value
Type: Number
Description: Total number of records that match the filter criteria of the view.
Remarks
To get the gridContext , see Getting the grid context.
See Collections (Client API reference) for information on the methods available to access data in a collection.
GridRow (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
NAME DESCRIPTION AVAILABLE FOR
Methods
NAME DESCRIPTION AVAILABLE FOR
Related topics
GridRowData
Grids and subgrids in Customer Engagement
getData (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: GridRowData
Remarks
To get the gridRow object, see GridRow.
GridRowData (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
NAME DESCRIPTION AVAILABLE FOR
entity Returns the GridEntity for the Read-only and editable grids
GridRowData.
Methods
NAME DESCRIPTION AVAILABLE FOR
getEntity Deprecated. Returns the GridEntity for Read-only and editable grids
the GridRowData.
getEntity (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: GridEntity
Remarks
To get the gridRowData object, see GridRowData.
GridEntity (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
GridEntity also supports the attributes collection that provides methods of working with a collection of
attributes for an entity in the editable grid. Each attribute (GridAttribute) represents the data in the cell of an
editable grid, and contains a reference to all the cells associated with the attribute. See Collections (Client API
reference) for information on the methods available to access data in a collection.
Methods
NAME DESCRIPTION AVAILABLE FOR
getEntityName Returns the logical name for the record Read-only and editable grids
in the row.
getEntityReference Returns a Lookup value that references Read-only and editable grids
the record in the row.
getId Returns the Id for the record in the row. Read-only and editable grids
Related topics
GridAttribute
Grids and subgrids in Customer Engagement
Attributes
getEntityName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The logical name for the record in the row.
Remarks
To get the gridEntity object, see GridEntity.
getEntityReference (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Lookup
Description: Lookup object that references the record in the row. The object has the following attributes:
entityType: String. The logical name for the record in the row. The same data returned by the
[Link] method.
id: String. The Id for the record in the row. The same data returned by the [Link] method.
name: String. The primary attribute value for the record in the row. The same data returned by the
[Link] method.
Remarks
To get the gridEntity object, see GridEntity.
getId (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The Id for the record in the row.
Remarks
To get the gridEntity object, see GridEntity.
getPrimaryAttributeValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: String
Description: The primary attribute value for the record in the row.
Remarks
To get the gridEntity object, see GridEntity.
GridAttribute (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
TIP
For performance reasons, a row (record) in an editable grid is not editable until the record is selected. Users must select a
single record in a grid to edit it. Once a record is selected in an editable grid, Dynamics 365 internally evaluates a number of
things including user access to the record, whether the record is active, and field validations to ensure that data security and
validity are honored when you edit data. Consider using the OnRecordSelect event with the getFormContext method to
access records in the grid that are in the editable state.
Methods
GridAttribute supports the following methods for attributes of a selected grid row.
NAME DESCRIPTION
NOTE
To select a row in an editable grid, use the [Link]
Related topics
GridCell
Grids and subgrids in Customer Engagement
Controls collection
GridCell (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Methods
GridCell supports the following methods.
NAME DESCRIPTION
setNotification Displays an error message for a cell to indicate that data isn’t
valid.
getLabel Returns the label of the column that contains the cell.
Related topics
Grids and subgrids in Customer Engagement
Controls
ViewSelector methods (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Methods
Related topics
gridContext
Grids and subgrids in Customer Engagement
getCurrentView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Lookup object
Description: The Lookup object has the following attributes:
entityType: Number. The object type code for the SavedQuery (1039) or UserQuery (4230) that represents the
view the user can select.
id: String. The Id for the view the user can select.
name: String. The name of the view the user can select.
Remarks
If the subgrid control is not configured to display the view selector, calling this method on the viewSelector object
will throw an error.
To get the viewSelector object, see ViewSelector.
isVisible (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]();
Return Value
Type: Boolean
Description: true if visible; false otherwise.
Remarks
If the subgrid control is not configured to display the view selector, calling this method on the ViewSelector
returned by the [Link] method will throw an error.
To get the viewSelector object, see ViewSelector.
setCurrentView (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](object);
Parameter
NAME TYPE REQUIRED DESCRIPTION
Remarks
If the subgrid control is not configured to display the view selector, calling this method on the viewSelector object
will throw an error.
To get the viewSelector object, see ViewSelector.
Example
function setView(executionContext) {
var ContactsIFollow = {
entityType: 1039, // SavedQuery
id: "3A282DA1-5D90-E011-95AE-00155D9CFA02",
name: "Contacts I Follow"
}
// Get the gridContext
var formContext = [Link]();
var gridContext = [Link]("Contacts");
Related topics
ViewSelector
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
pickFile Opens a dialog box to select files from your computer (web
client) or mobile device (mobile clients).
Related topics
Client API Xrm object
captureAudio (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a base64 encoded audio object with the attributes specified earlier.
Remarks
This method is supported only for the mobile clients.
Related topics
[Link]
captureImage (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](imageOptions).then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a base64 encoded image object with the attributes specified earlier.
Remarks
This method is supported only for the mobile clients.
Related topics
[Link]
captureVideo (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a base64 encoded Video object with the attributes specified earlier.
Remarks
This method is supported only for the mobile clients.
Related topics
[Link]
getBarcodeValue (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a string containing the scanned barcode value.
Remarks
This method is supported only for the mobile clients.
Example
[Link]().then(
function success(result) {
[Link]({ text: "Barcode value: " + result });
},
function (error) {
[Link]( {text: [Link]} );
}
);
Related topics
[Link]
getCurrentPosition (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]().then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a geolocation object with the attributes specified earlier in the successCallback function.
Remarks
For the getCurrentPosition method to work, the geolocation capability must be enabled on your mobile device,
and the Dynamics 365 Customer Engagement mobile clients must have permissions to access the device location,
which isn't enabled by default.
This method is supported only for the mobile clients.
Example
[Link]().then(
function success(location) {
[Link]({
text: "Latitude: " + [Link] +
", Longitude: " + [Link]
});
},
function (error) {
[Link]({ text: [Link] });
}
);
Related topics
[Link]
pickFile (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](pickFileOptions).then(successCallback, errorCallback)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise with array of objects as specified earlier for the successCallback function.
Related topics
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
Related topics
Client API Xrm object
htmlAttributeEncode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: Encoded string.
Related topics
htmEncode
htmlDecode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: Decoded string.
Related topics
htmlEncode
htmlAttributeEncode
htmlEncode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: Encoded string.
Related topics
htmlAttributeEncode
htmlDecode
xmlAttributeEncode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: Encoded string.
Related topics
xmlEncode
xmlEncode (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](arg)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: Encoded string.
Related topics
xmlAttributeEncode
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
Related topics
Client API Xrm object
openAlertDialog (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](alertStrings,alertOptions).then(closeCallback,errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Example
The following sample code displays an alert dialog. Clicking Yes button in the alert dialog or canceling the alert
dialog by pressing ESC calls the close function::
var alertStrings = { confirmButtonLabel: "Yes", text: "This is an alert." };
var alertOptions = { height: 120, width: 260 };
[Link](alertStrings, alertOptions).then(
function success(result) {
[Link]("Alert dialog closed");
},
function (error) {
[Link]([Link]);
}
);
Related topics
[Link]
openConfirmDialog (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](confirmStrings,confirmOptions).then(successCallback,errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Example
The following code sample displays a confirmation dialog box. Appropriate message is logged in the console
depending on whether confirm or cancel/X was clicked to close the dialog.
Related topics
[Link]
openErrorDialog (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](errorOptions).then(successCallback,errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Example
The following code sample passes an incorrect errorCode (1234) to display an error dialog with default message:
Related topics
[Link]
openFile (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](file,openFileOptions)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
openForm (Client API reference)
8/24/2018 • 4 minutes to read • Edit Online
Syntax
[Link](entityFormOptions,formParameters).then(successCallback,errorCallback);
Parameters
attr Stri Na
ibu ng me
teN of
am the
e attr
ibut
e
use
d
for
rela
tion
shi
p.
na Stri Na
me ng me
of
the
rela
tion
shi
p.
nav Stri Na
iga ng me
tio of
nPr the
op nav
ert igat
yN ion
am pro
e per
ty
for
this
rela
tion
shi
p.
rel Nu Rel
ati mb atio
ons er nsh
hip ip
Typ typ
e e.
Spe
cify
one
of
the
foll
owi
ng
val
ues
:
0:OneToMany
1:ManyToMany
rol Nu Rol
eTy mb e
pe er typ
e in
rela
tion
shi
p.
Spe
cify
one
of
the
foll
owi
ng
val
ues
:
1:Referencing
2:AssociationEntity
selectedStageId:
(Optional) String. ID of
the selected stage in
business process
instance.
useQuickCreateFor
m: (Optional) Boolean.
Indicates whether to
open a quick create
form. If you do not
specify this, by default
false is passed.
width: (Optional)
Number. Width of the
form window to be
displayed in pixels.
formParameters Object No A dictionary object that
passes extra parameters to
the form. Invalid parameters
will cause an error.
Remarks
You must use this method to open entity or quick create forms instead of the deprecated [Link]
and [Link] methods.
Examples
Example 1: Open an entity form for existing record
The following sample code opens a contact form to display an existing contact record:
Related topics
[Link]
openUrl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](url,openUrlOptions)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Remarks
This method is especially helpful for mobile clients to open a URL in a browser outside of shim.
Related topics
[Link]
openWebResource (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](webResourceName,windowOptions,data)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Remarks
You must use this method to display web resources instead of the deprecated [Link]
method.
An HTML web resource can accept the parameter values described in Pass parameters to HTML web resources.
This function only provides for passing in the optional data parameter. To pass values for the other valid
parameters, you must append them to the webResourceName parameter.
NOTE
The Xrm object isn’t available in HTML web resources. Therefore, scripts containing Xrm.* methods aren’t supported in
HTML web resources. [Link].* will work if the HTML web resource is loaded in a form container. However, for other
places, such as loading an HTML web resource as part of the SiteMap, [Link].* also won’t work. More information:
GetGlobalContext function and [Link]
Examples
Open an HTML web resource named “new_webResource.htm”:
[Link]("new_webResource.htm");
Open an HTML web resource including a single item of data for the data parameter
[Link]("new_webResource.htm",null,"dataItemValue");
Related topics
[Link]
[Link]
8/24/2018 • 2 minutes to read • Edit Online
METHOD DESCRIPTION
loadPanel Displays the web page represented by a URL in the static area
in the side pane, which appears on all pages in the Dynamics
365 Customer Engagement web client.
NOTE
The [Link] namespace was introduced in the December 2016 update for Dynamics 365 (online and on-premises), and
the method under this namespace is a preview feature. A preview feature is a feature that is not complete, but is made
available before it’s officially in a release so customers can get early access and provide feedback. Preview features aren’t
meant for production use and may have limited or restricted functionality. We expect changes to this feature, so you
shouldn’t use it in production. Use it only in test and development environments. Microsoft doesn't provide support for this
preview feature. Microsoft Dynamics 365 Technical Support won’t be able to help you with issues or questions. Preview
features aren't meant for production use and are subject to a separate supplemental terms of use.
Related topics
Client API Xrm object
loadPanel (Client-side reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](url, title)
Parameters
PARAMETER NAME TYPE REQUIRED DESCRIPTION
Remarks
This method is supported only for the web client.
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Methods
METHOD DESCRIPTION
getAllowedStatusTransitions Returns the valid state transitions for the specified entity type
and state code.
getResourceString Returns the localized string for a given key associated with
the specified web resource.
Deprecated methods
The following table lists the new methods you should use instead of the deprecated methods in the [Link]
namespace. These methods were deprecated in Dynamics 365 (online), version 9.0.
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
DEPRECATED METHOD NEW METHOD TO BE USED
[Link] [Link]
[Link] [Link]
[Link] [Link]
Syntax
[Link]()
Related topics
showProgressIndicator
[Link]
getAllowedStatusTransitions (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](entityName,stateCode).then(successCallback, errorCallback)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
[Link]
getEntityMetadata
8/24/2018 • 5 minutes to read • Edit Online
Syntax
[Link](entityName,attributes).then(successCallback, errorCallback)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Returns
Type: Object
Description: An object containing the entity metadata information with the following attributes.
EntitySetName String The name of the Web API entity set for
this entity.
Related topics
[Link]
getGlobalContext (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
IMPORTANT
To access the global context information in a standalone HTML Web resource, you should include a reference to
[Link] in the web resource, and then use the GetGlobalContext function. More information:
GetGlobalContext function and [Link]
PROPERTY DESCRIPTION
getClientUrl Returns the base URL that was used to access the application.
getClient
Returns a value to indicate which client the script is executing in.
Syntax
[Link]()
Return Value
Type: String
Description: The values returned are:
VALUE CLIENT
Outlook Outlook
getClientState
Returns a value to indicate the state of the client.
Syntax
[Link]()
Return Value
Type: String
Description: The values returned are:
VALUE CLIENT
Return Value
Type: Number
Description: The values returned are:
0 Unknown
1 Desktop
2 Tablet
3 Phone
isOffline
Returns information whether the server is online or offline.
Syntax
[Link]()
Return Value
Type: Boolean
Description: true if the server is offline; false otherwise.
Related topics
Organization Settings
User Settings
[Link]
[Link] (Client API
reference)
8/24/2018 • 2 minutes to read • Edit Online
attributes
Returns attributes and their values as key:value pairs that are available for the organization entity. Additional
values will be available as attributes if they are specified as attribute dependencies in the web resource dependency
list. The key will be the attribute logical name.
Syntax
[Link]
Return Value
Type: Object
Description: An object with attributes and their values.
baseCurrencyId
Returns the ID of the base currency for the current organization.
Syntax
[Link]
Return Value
Type: String
Description: ID of the base currency.
defaultCountryCode
Returns the default country/region code for phone numbers for the current organization.
Syntax
[Link]
Return Value
Type: String
Description: Default country/region code for phone numbers.
isAutoSaveEnabled
Indicates whether the auto-save option is enabled for the current organization.
Syntax
[Link]
Return Value
Type: Boolean
Description: true if enabled; false otherwise.
languageId
Returns the preferred language ID for the current organization.
Syntax
[Link]
Return Value
Type: Number
Description: Preferred Language ID. For example:
1033
organizationId
Returns the ID of the current organization.
Syntax
[Link]
Return Value
Type: String
Description: Id of the current organization.
uniqueName
Returns the unique name of the current organization.
Syntax
[Link]
Return Value
Type: String
Description: Unique name of the current organization.
useSkypeProtocol
Indicates whether the Skype protocol is used for the current organization.
Syntax
[Link]
Return Value
Type: Boolean
Description: true if Skype protocol is used; false otherwise.
Related topics
Client context
User settings
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
dateFormattingInfo
Returns the date formatting information for the current user.
Syntax
[Link]
Return Value
Type: Object
Description: An object with informatiuon about date formatting such as FirstDayOfWeek, LongDatePattern,
MonthDayPattern, TimeSeparator, and so on.
defaultDashboardId
Returns the ID of the default dashboard for the current user.
Syntax
[Link]
Return Value
Type: String
Description: ID of the default dashboard.
isGuidedHelpEnabled
Indicates whether guided help is enabled for the current user.
Syntax
[Link]
Return Value
Type: Boolean
Description: true if enabled; false otherwise.
isHighContrastEnabled
Indicates whether high contrast is enabled for the current user.
Syntax
[Link]
Return Value
Type: Boolean
Description: true if enabled; false otherwise.
isRTL
Indicates whether the language for the current user is a right-to-left (RTL ) language.
Syntax
[Link]
Return Value
Type: Boolean
Description: true if it is RTL; false otherwise.
languageId
Returns the language ID for the current user.
Syntax
[Link]
Return Value
Type: Number
Description: Language ID.
securityRolePrivileges
Returns an array of strings that represent the GUID values of each of the security role privilege that the user is
associated with or any teams that the user is associated with.
Syntax
[Link]
Return Value
Type: Array
Description: GUID values of each of the security role privilege.
securityRoles
Returns an array of strings that represent the GUID values of each of the security role that the user is associated
with or any teams that the user is associated with.
Syntax
[Link]
Return Value
Type: Array
Description: GUID values of each of the security role. For example:
["0d3dd20a-17a6-e711-a94e-000d3a1a7a9b", "ff42d20a-17a6-e711-a94e-000d3a1a7a9b"]
transactionCurrencyId
Returns the transaction currency ID for the current user.
Syntax
[Link]
Return Value
Type: String
Description: Transaction currency ID.
userId
Returns the GUID of the [Link] value for the current user.
Syntax
[Link]
Return Value
Type: String
Description: The ID of the user. For example:
"{75B5BA27-FD41-4D45-8E3A-C8446C95F0CC}"
userName
Returns the name of the current user.
Syntax
[Link]
Return Value
Type: String
Description: Name of the current user.
getTimeZoneOffsetMinutes method
Returns the difference in minutes between the local time and Coordinated Universal Time (UTC ).
Syntax
[Link]()
Return Value
Type: number
Description: Time zone offset in minutes.
Related topics
Client context
Organization settings
[Link]
getAdvancedConfigSetting (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link](setting);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Returns the advanced configuration setting value.
Related topics
[Link]
getClientUrl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]();
Return Value
Type: String
Description: The values returned will resemble those listed in the following table.
VALUE CLIENT
Related topics
[Link]
getCurrentAppName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]().then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
If this method is called in the context of a business app, returns the name of the business app. Otherwise, it fails
with an error.
Related topics
Create and manage custom business apps using code
[Link]
getCurrentAppProperties (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]().then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
If this method is called in the context of a business app, returns the properties of the business app. Otherwise, it
fails with an error.
Related topics
Create and manage custom business apps using code
[Link]
getCurrentAppUrl (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]();
Return Value
Type: String
Description: URL of the current business app. Possible return values:
VALUE CLIENT
Related topics
Create and manage custom business apps using code
[Link]
getVersion (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]();
Return Value
Type: String
Description: Version of the Customer Engagement instance. For example:
"9.0.0.1103"
Related topics
[Link]
isOnPremise (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link]();
Return Value
Type: Boolean
Description: true if the Customer Engagement instance is on-premises; false otherwise.
Related topics
[Link]
prependOrgName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
var globalContext = [Link]();
[Link](sPath);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: String
Description: A path string with the organization name prefixed in the following format:
"/"+ orgName + sPath
Related topics
[Link]
getLearningPathAttributeName (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link]()
Returns
Type: String
Description: DOM attribute expected by the Learning Path (guided help) Content Designer.
Related topics
Create your own guided help (Learning Path) for your customers
[Link]
getResourceString (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](webResourceName,key)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return value
A localized string.
Remarks
When you create RESX web resources you must explicitly set the language value and include the locale identifier
(LCID ) for the appropriate language in the name of the web resource. For example,
new_/strings/[Link] would contain resources for English language. See Microsoft Locale ID
Values for a list of LCID values.
For example [Link]("new_/strings/MyAppResources","hello") will return the localized string
value for the resource key hello within the new_/strings/[Link] web resource if the user’s
preferred language is English. Notice that the function doesn’t refer to any specific language or full name of any
RESX web resource. This functionality depends on the RESX web resource being associated to the calling
JavaScript web resource as a dependency. More information: Web resource dependencies.
The appropriate string value will be determined by the individual user’s language preference and the languages
available in the organization. If a localized string is not found that matches the user’s language preference, the
localized string will automatically fallback to the base language for the organization. If no matching localized string
is found for the organizations base language, a null value will be returned.
Related topics
[Link]
String (RESX) web resources
Web resource dependencies
invokeProcessAction (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](name,parameters).then(successCallback, errorCallback)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Returns
On success, returns Web API result along with any action output.
Related topics
Actions overview
[Link]
lookupObjects (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](lookupOptions).then(successCallback, cancelCallback)
Parameters
lookupOptions: Object. Defines the options for opening the lookup dialog. Has the following properties:
Related topics
[Link]
refreshParentGrid (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](lookupOptions)
Parameters
lookupOptions: An object with the following properties to specify the record:
Related topics
[Link]
showProgressIndicator (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
WARNING
The progress dialog blocks the UI until it is closed using the closeProgressIndicator method. So, you must use this method
with caution.
Syntax
[Link](message)
Parameters
NAME TYPE REQUIRED DESCRIPTION
Related topics
closeProgressIndicator
[Link]
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Properties
PROPERTY DESCRIPTION
Methods
METHOD DESCRIPTION
Related topics
Use the Dynamics 365 Customer Engagement Web API
Client API Xrm object
[Link] (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
Use [Link] instead of the deprecated [Link] namespace to create and manage records in the
mobile clients while working in the offline mode.
The offlineWebApi object provides the following methods. When in the offline mode, these methods will work
only for entities that are enabled for mobile offline synchronization and available in current user’s mobile offline
profile.
createRecord
deleteRecord
isAvailableOffline
retrieveRecord
retrieveMultipleRecords
updateRecord
IMPORTANT
While creating or updating record in the offline mode, only basic validation is performed on the input data. Basic validation
includes things such as ensuring that the entity attribute name specified is in lower case and does exist for an entity, checking
for data type mismatch for the specified attribute value, preventing records getting created with the same GUID value,
checking whether the related entity is offline enabled when retrieving related entity records, and validating if the record that
you want to retrieve, update, or delete actually exists in the offline data store. Business-level validations happen only when
you are connected to the server and the data is synchronized. A record is created or updated only if the input data is
completely valid.
Related topics
[Link]
[Link]
createRecord (Client API reference)
8/24/2018 • 3 minutes to read • Edit Online
Syntax
[Link](entityLogicalName, data).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Examples
These examples use the same request objects as demonstrated in Create an entity using the Web API to define the
data object for creating an entity record.
Basic create
Creates a sample account record.
var data =
{
"name": "Sample Account",
"primarycontactid@[Link]": "/contacts(465b158c-541c-e511-80d3-3863bb347ba8)"
}
var data =
{
"name": "Sample Account",
"primarycontactid":
{
"logicalname": "contact",
"id": "465b158c-541c-e511-80d3-3863bb347ba8"
}
}
Related topics
Create an entity using the Web API
[Link]
deleteRecord (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](entityLogicalName, id).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise object containing the attributes specified earlier in the description of the
successCallback parameter.
Examples
These examples use some of the same request objects as demonstrated in Update and delete entities using the
Web API to define the data object for updating an entity record.
Deletes an account with record ID = 5531d753-95af-e711-a94e-000d3a11e605.
[Link]("account", "5531d753-95af-e711-a94e-000d3a11e605").then(
function success(result) {
[Link]("Account deleted");
// perform operations on record deletion
},
function (error) {
[Link]([Link]);
// handle error conditions
}
);
Related topics
[Link]
retrieveRecord (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](entityLogicalName, id, options).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise containing a JSON object with the retrieved attributes and their values.
Examples
Basic retrieve
Retrieves the name and revenue of an account record wwith record ID = 5531d753-95af-e711-a94e-000d3a11e605.
The above example displays the following in your console; you might see other values depending on your data:
Retrieved values: Name: Sample Account, Revenue: 5000000
Retrieve related entities for an entity instance by expanding single-valued navigation properties
The following example demonstrates how to retrieve the contact for an account record with record ID = a8a19cdd-88df-e311-b8e5-
6c3be5a8b200. For the related contact record, we are only retrieving the contactid and fullname properties.
The above example displays the following in your console; you might see other values depending on your data:
Retrieved values: Name: Adventure Works, Primary Contact ID: 49a0e5b9-88df-e311-b8e5-6c3be5a8b200, Primary Contact Name: Adrian Dumitrascu
Related topics
[Link]
[Link]
retrieveMultipleRecords (Client API reference)
8/24/2018 • 4 minutes to read • Edit Online
Syntax
[Link](entityLogicalName, options, maxPageSize).then(successCallback,
errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise that contains an array of JSON objects (entities) containing the retrieved entity
records and the nextLink attribute (optional) with the URL pointing to next set of records in case paging (
maxPageSize ) is specified in the request, and the record count returned exceeds the paging value.
Examples
Most of the scenarios/examples mentioned in Query Data using the Web API can be achieved using the
retrieveMutipleRecords method. Some of the examples are listed below.
Basic retrieve multiple
This example queries the accounts entity set and uses the $select and $top system query options to return the
name property for the first three accounts:
[Link]("account", "?$select=name&$top=3").then(
function success(result) {
for (var i = 0; i < [Link]; i++) {
[Link]([Link][i]);
}
// perform additional operations on retrieved records
},
function (error) {
[Link]([Link]);
// handle error conditions
}
);
This example will display 3 records and a link to the next page. Here is an example outout from the Console in the
browser developer tools:
Use the query part in the URL in the nextLink property as the value for the options parameter in your
subsequent retrieveMultipleRecords call to request the next set of records. Don’t change or append any
additional system query options to the value. For every subsequent request for additional pages, you should use
the same maxPageSize value used in the original retrieve multiple request. Also, cache the results returned or the
value of the nextLink property so that previously retrieved pages can be returned.
For example, to get the next page of records, we will pass in the query part of the nextLink URL to the options
parameter:
[Link]("account", "?
$select=name&$skiptoken=%3Ccookie%20pagenumber=%222%22%20pagingcookie=%22%253ccookie%2520page%253d%25221%2522%2
53e%253caccountid%2520last%253d%2522%257bAAA19CDD-88DF-E311-B8E5-
6C3BE5A8B200%257d%2522%2520first%253d%2522%257b475B158C-541C-E511-80D3-
3863BB347BA8%257d%2522%2520%252f%253e%253c%252fcookie%253e%22%20istracking=%22False%22%20/%3E", 3).then(
function success(result) {
for (var i = 0; i < [Link]; i++) {
[Link]([Link][i]);
}
[Link]("Next page link: " + [Link]);
// perform additional operations on retrieved records
},
function (error) {
[Link]([Link]);
// handle error conditions
}
);
IMPORTANT
The value of the nextLink property is URI encoded. If you URI encode the value before you send it, the XML cookie
information in the URL will cause an error.
For more examples of retrieving multiple records using Web API, see Query Data using the Web API.
Related topics
Query Data using the Web API
[Link]
[Link]
updateRecord (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](entityLogicalName, id, data).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise object containing the attributes specified earlier in the description of the
successCallback parameter.
Examples
These examples use some of the same request objects as demonstrated in Update and delete entities using the
Web API to define the data object for updating an entity record.
Basic update
Updates an existing account record with record ID = 5531d753-95af-e711-a94e-000d3a11e605.
Related topics
[Link]
isAvailableOffline (Client API reference)
8/24/2018 • 2 minutes to read • Edit Online
Syntax
[Link](entityLogicalName);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
Type: Boolean.
Description: true if the entity is present in user’s profile and is currently available for use in offline mode;
otherwise false.
[Link]
[Link]
[Link] (Client API reference)
8/24/2018 • 3 minutes to read • Edit Online
NOTE
This method is supported only for the online mode ([Link]).
Syntax
[Link](request).then(successCallback, errorCallback);
Parameters
NAME TYPE REQUIRED DESCRIPTION
Return Value
On success, returns a promise object with the attributes specified earlier in the description of successCallback
function.
Examples
Execute an action
The following example demonstrates how to execute the WinOpportunity action. The request object is created
based on the action definition here: Unbound actions
var Sdk = [Link] || {};
/**
* Request to win an opportunity
* @param {Object} opportunityClose - The opportunity close activity associated with this state change.
* @param {number} status - Status of the opportunity.
*/
[Link] = function (opportunityClose, status) {
[Link] = opportunityClose;
[Link] = status;
[Link] = function () {
return {
boundParameter: null,
parameterTypes: {
"OpportunityClose": {
"typeName": "[Link]",
"structuralProperty": 5 // Entity Type
},
"Status": {
"typeName": "Edm.Int32",
"structuralProperty": 1 // Primitive Type
}
},
operationType: 0, // This is an action. Use '1' for functions and '2' for CRUD
operationName: "WinOpportunity",
};
};
};
var opportunityClose = {
"opportunityid@[Link]": "/opportunities(c60e0283-5bf2-e311-945f-6c3be5a8dd64)",
"description": "Product and maintainance for 2018",
"subject": "Contract for 2018"
}
Execute a function
The following example demonstrates how to execute the WhoAmI function:
var Sdk = [Link] || {};
/**
* Request to execute WhoAmI function
*/
[Link] = function () {
[Link] = function () {
return {
boundParameter: null,
parameterTypes: {},
operationType: 1, // This is a function. Use '0' for actions and '2' for CRUD
operationName: "WhoAmI",
};
};
};
Related topics
[Link]
[Link] (Client API
reference)
8/24/2018 • 2 minutes to read • Edit Online
NOTE
This method is supported only for the online mode ([Link]).
If you want to execute multiple requests in a transaction, you must pass in a change set as a parameter to this
method. Change sets represent a collection of operations that are executed in a transaction. You can also pass in
individual requests and change sets together as parameters to this method.
NOTE
You cannot include read operations (retrieve, retrieve multiple, and Web API functions) as part of a change set; this is as per
the OData v4 specifications.
Syntax
Execute multiple requests:
Parameters
NAME TYPE REQUIRED DESCRIPTION
requests Array of objects Yes An array of one of one
of the following types:
objects where each
object is an action,
function, or CRUD
request that you
want to execute
against the Web API
endpoint. Each object
exposes a
getMetadata
method that lets you
define the metadata
for the action,
function or CRUD
request you want to
execute. This is the
same object that you
pass in the execute
method. For
information about
the object, see
execute.
Change set (an array
of objects), where
each object in the
change set is as
defined above. In this
case, all the request
objects specified in
the change set will
get executed in a
transaction.
See request examples
earlier in the Syntax
section for more
information.
successCallback Function No A function to call when
operation is executed
suucessfully. An array of
response objects are
passed to the function
where weach response
object has the following
attributes:
body: (Optional).
Object. Response
body.
headers: Object.
Response headers.
ok: Boolean.
Indicates whether the
request was
successful.
status: Number.
Numeric value in the
response status code.
For example: 200
statusText: String.
Description of the
response status code.
For example: OK
type: String.
Response type.
Values are: the empty
string (default),
"arraybuffer", "blob",
"document", "json",
and "text".
url: String. Request
URL of the action,
function, or CRUD
request that was sent
to the Web API
endpoint.
Return Value
On success, returns a promise containing an array of objects with the attributes specified earlier in the description
of successCallback function.
Related topics
[Link]