Difference between revisions of "Post Selection JavaScript"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 11: Line 11:
# Click the '''Save''' button.
# Click the '''Save''' button.


===Post Selection Variables===
====Built In Variables====


In the JavaScript code, the following variables are available:  
In the JavaScript code, the following variables are available:  
Line 18: Line 18:
:* <tt>id</tt>: The identifier of the selected record
:* <tt>id</tt>: The identifier of the selected record
:* <tt>name</tt>: The label of the selected record
:* <tt>name</tt>: The label of the selected record
====Learn More====
:* [[Field Name|Field Name and Field Value]] syntax
:* Use [[AJAX and REST]] to communicate with the platform in JavaScript code.
:* [[Global JavaScript Variables]]
:* [[JavaScript#Accessing_Additional_Lookup_Variables_in_a_Form|Accessing Additional Lookup Variables in a Form]]


===Examples===
===Examples===
Line 35: Line 41:
setTextFieldValue(_sdForm, "order_number", order);  // Set it in current record
setTextFieldValue(_sdForm, "order_number", order);  // Set it in current record
</syntaxhighlight>
</syntaxhighlight>
===Learn More===
:* [[Field Name|Field Name and Field Value]] syntax
:* Use [[AJAX and REST]] to communicate with the platform in JavaScript code.
:* [[Global JavaScript Variables]]
:* [[JavaScript#Accessing_Additional_Lookup_Variables_in_a_Form|Accessing Additional Lookup Variables in a Form]]
<noinclude>
<noinclude>


[[Category:JavaScript]]
[[Category:JavaScript]]
</noinclude>
</noinclude>

Revision as of 23:02, 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:

  1. Click GearIcon.png > Customization > Objects > {object} > Fields
  2. Click the name of the Lookup field.
  3. Enter or change the code in Post Selection JavaScript.
  4. Click the Save button.

Built In 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

Learn More

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.

alert("You have selected record: " + name);

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.

var order = _sdForm.order.order_num;  // Get value from Order record
setTextFieldValue(_sdForm, "order_number", order);  // Set it in current record