Difference between revisions of "Post Selection JavaScript"
imported>Aeric |
imported>Aeric |
||
Line 3: | Line 3: | ||
:''Compare to [[Form Scripting]] and [[Field Scripting]]'' | :''Compare to [[Form Scripting]] and [[Field Scripting]]'' | ||
=== | === Working with Post Selection Scripts === | ||
Follow these steps to add or change scripting for a Lookup field: | Follow these steps to add or change scripting for a Lookup field: | ||
Line 11: | Line 11: | ||
# Click the '''Save''' button. | # Click the '''Save''' button. | ||
=== | ===Post Selection Variables=== | ||
In the JavaScript code, the following variables are available: | In the JavaScript code, the following variables are available: | ||
Line 19: | Line 19: | ||
:* <tt>name</tt>: The label of the selected record | :* <tt>name</tt>: The label of the selected record | ||
This example | ===Examples=== | ||
: | |||
< | ====Displays the Label of the Selected Record==== | ||
alert("You have selected record: " + name);</ | This example uses the <tt>name</tt> variable to display the label of the record, has configured in the [[Record Identifiers]]. | ||
:<syntaxhighlight lang="javascript" enclose="div"> | |||
alert("You have selected record: " + name); | |||
</syntaxhighlight> | |||
====Copy a Field from Another Record==== | |||
This code accesses the record targeted by a Lookup, retrieves a field value, and places it into the current form. Here, the current record is an OrderItem. When the user selects the Order the item is part of, this code retrieves the Order number and stores it in the current record. | |||
:<syntaxhighlight lang="javascript" enclose="div"> | |||
var order = _sdForm.order.order_num; // Get value from Order record | |||
setTextFieldValue(_sdForm, "order_number", order); // Set it in current record | |||
</syntaxhighlight> | |||
===Learn More=== | ===Learn More=== |
Revision as of 23:00, 21 May 2014
Lookup fields have the additional ability for validations using JavaScript.
- Compare to Form Scripting and Field Scripting
Working with Post Selection Scripts
Follow these steps to add or change scripting for a Lookup field:
- Click > Customization > Objects > {object} > Fields
- Click the name of the Lookup field.
- Enter or change the code in Post Selection JavaScript.
- Click the Save button.
Post Selection Variables
In the JavaScript code, the following variables are available:
- objectId The identifier for the Object
- id: The identifier of the selected record
- name: The label of the selected record
Examples
Displays the Label of the Selected Record
This example uses the name variable to display the label of the record, has configured in the Record Identifiers.
- <syntaxhighlight lang="javascript" enclose="div">
alert("You have selected record: " + name); </syntaxhighlight>
Copy a Field from Another Record
This code accesses the record targeted by a Lookup, retrieves a field value, and places it into the current form. Here, the current record is an OrderItem. When the user selects the Order the item is part of, this code retrieves the Order number and stores it in the current record.
- <syntaxhighlight lang="javascript" enclose="div">
var order = _sdForm.order.order_num; // Get value from Order record setTextFieldValue(_sdForm, "order_number", order); // Set it in current record </syntaxhighlight>
Learn More
- Field Name and Field Value syntax
- Use AJAX and REST to communicate with the platform in JavaScript code.
- Global JavaScript Variables
- Accessing Additional Lookup Variables in a Form