
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2018 09:39 AM
I've got a problem with clearing values in fields x,y,z when a Reference was emptied (user removed as a value). It concerns catalog client script. Am trying to manipulate with "newValue", "odValue", but in vain..
Code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' ) {
return;
}
var req = g_form.getReference('fru_requested_for',pullAttributes); //call to the sys_user reference field
//below is the callBack function to pull user's attributes
function pullAttributes(req) {
var h = g_form.getDisplayBox('fru_requested_for').value;
if (newValue !=='') {
alert("ustawiono");
g_form.setValue('fru_first_name',req.first_name);
g_form.setValue('fru_last_name',req.last_name);
g_form.setValue('fru_email',req.email);
g_form.setValue('fru_employee_id',req.employee_number);
} else if (newValue == '')
{
alert("test");
g_form.setValue('fru_first_name','');
g_form.clearValue('fru_last_name');
g_form.clearValue('fru_email');
g_form.clearValue('fru_employee_id');
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2018 11:21 AM
Try this and let me know what you get.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
// Call to the sys_user reference field
var req = g_form.getReference('fru_requested_for', pullAttributes);
}
// Callback function to pull user's attributes
function pullAttributes(req) {
if (newValue != '') {
alert("Not empty");
g_form.setValue('fru_first_name', req.first_name);
g_form.setValue('fru_last_name', req.last_name);
g_form.setValue('fru_email', req.email);
g_form.setValue('fru_employee_id', req.employee_number);
}
else {
alert("Empty");
g_form.clearValue('fru_first_name','');
g_form.clearValue('fru_last_name');
g_form.clearValue('fru_email');
g_form.clearValue('fru_employee_id');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2018 11:21 AM
Try this and let me know what you get.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
return;
}
// Call to the sys_user reference field
var req = g_form.getReference('fru_requested_for', pullAttributes);
}
// Callback function to pull user's attributes
function pullAttributes(req) {
if (newValue != '') {
alert("Not empty");
g_form.setValue('fru_first_name', req.first_name);
g_form.setValue('fru_last_name', req.last_name);
g_form.setValue('fru_email', req.email);
g_form.setValue('fru_employee_id', req.employee_number);
}
else {
alert("Empty");
g_form.clearValue('fru_first_name','');
g_form.clearValue('fru_last_name');
g_form.clearValue('fru_email');
g_form.clearValue('fru_employee_id');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2018 11:31 AM
Mark, the same. Value are setup, but no both alerts, nor removing values when emptying reference. Maybe that's a bug in Jakarta, isn't it ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2018 04:07 PM
Mark, so to speak... You're the real ServiceNow GURU. the code has worked with the newValue=='' operator.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var req = g_form.getReference('fru_requested_for',pullAttributes); //call to the sys_user reference field
//below is the callBack function to pull user's attributes
function pullAttributes(req) {
//var h = g_form.getDisplayBox('fru_requested_for').value;
g_form.setValue('fru_first_name',req.first_name);
g_form.setValue('fru_last_name',req.last_name);
g_form.setValue('fru_email',req.email);
g_form.setValue('fru_employee_id',req.employee_number);
}
if (newValue =='') {
g_form.clearValue('fru_first_name');
g_form.clearValue('fru_last_name');
g_form.clearValue('fru_email');
g_form.clearValue('fru_employee_id');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2018 06:44 AM
Thanks Piotr. Please mark my answer above as the correct one if I've answered your question.