In this tutorial, you will learn how can you set a value on a field of a form on different conditions and scenarios.
Setting the field value on load of the form
Scenario: When incident form is loaded then the value of Caller field should populated with logged in user.
Solution : This type of requirement can be achieved with Client Script as it needs to be set when form is loaded in the browser.
Type of Script : Client Script
Name : Populate Caller on the Incident
Table : Incident
UI Type : All
Type : OnLoad
Active : True
Global: True
Script :
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_form.isNewRecord()) {
var currentUser = g_user.userID;
g_form.setValue('caller_id', currentUser);
}
}
Setting the field value on change of a field
Scenario: When incident form is loaded then the Assignment Group should be populated with Network group.
Solution : This type of requirement can be achieved with Client Script as it needs to be set when value oof Category field changes to Hardware.
Type of Script : Client Script
Name : Populate Caller on the Incident
Table : Incident
UI Type : All
Type : OnChange
Field: Category
Active : True
Global: True
Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 'hardware') {
//Setting SYSID OF Network Group
g_form.setValue('assignment_group', '287ebd7da9fe198100f92cc8d1d2154e'
,'Network');
}
}
Comments