On Change Event Script Example

From LongJump Support Wiki
Revision as of 23:09, 12 April 2011 by imported>Aeric
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Copy and paste the following JavaScript code into the on change event script for the Employee ID field in the Benefits object. This code is intended for use as part of an On Change Event Script.

//Login with existing credentials
AjaxInfo.setServerId('{$AppSessionID}');

//Define the form that we are currently working with
var form = document.mainForm;

//Create a new record
var record = new LongJump.Record();

//Set the Object ID to the table where you want to search
record.set('object','1555611998oit1617201617');

//Add the field list to be retrieved to the record
record.set('field_list',"record_id,first_name,last_name,security_id_");

//Set the filter string
record.set('filter', "employee_id equals'" + form.employee_id.value + "'");

//Make the search API call
var result = AjaxAPI.searchRecords(record);

//Status returns 'ERROR' when the search record does not retrieve records
//If the searchRecord retrieves a record then the status is set to 'RECORD'
if(result[0].getStatus() != 'RECORD')
{
   alert("Enter a valid 'Employee ID'");
}

//Employee found that matched the ID populated in the form
else
{
   form.employee_name.value = result[0].get("first_name") + " " + result[0].get("last_name");
   form.social_security_number.value = result[0].get("security_id_");
}