
- 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 09:43 AM
The very beginning of your script has this section, which is returning from the script if the field value is empty. I don't think you're even getting to any of the other code...
if (isLoading || newValue == '' ) { return; }
If you take the 'newValue' check out it should work better...
if (isLoading) { return; }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 09:53 AM
Thanks Mark,
I've followed your advice, but it still does not clear values.. However, when I select referecen user, values are being setup and 1st alert launched. The problem, however, is with clearing values. The version is Jakarta.
Modified code:
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;
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');
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2018 10:04 AM
Try this script and let me know how it works. If it isn't clearing the values, do you at least see the 'Empty' alert?
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:01 AM
Hi Mark,
Thank you. Neither 1st, not 2nd alert is shown, however, values are setup.. Maybe as a result of the callBack.