- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:53 AM
Hi not able to clear the value of string field which is dependent on Reference field. on change of user name it's working, but if the reference field is empty it's not working.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var caller = g_form.getReference('first_user_name', doAlert);
function doAlert(caller) {
var a= g_form.setValue('user_id',caller.user_name);
//alert(a);
var b = caller.user_name.split('@');
//alert(b);
g_form.setValue('selected_user_names',b[0]);
}
if(newValue==''){
g_form.clearValue('user_id');
}
}
I need to clear the user id once the Reference field (first_user_name) is empty but the above script is not working.
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:58 AM
Hello
Can you write your g_form.clearValue('user_id'); line in below loop and remove from the last of the script
if (isLoading || newValue == '') {
g_form.clearValue('user_id');
return;
}
Please try this and if it works mark my answer correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:58 AM
Hello
Can you write your g_form.clearValue('user_id'); line in below loop and remove from the last of the script
if (isLoading || newValue == '') {
g_form.clearValue('user_id');
return;
}
Please try this and if it works mark my answer correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:59 AM
Update your code as:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('user_id');
}
else{
var caller = g_form.getReference('first_user_name', doAlert);
function doAlert(caller) {
var a= g_form.setValue('user_id',caller.user_name);
//alert(a);
var b = caller.user_name.split('@');
//alert(b);
g_form.setValue('selected_user_names',b[0]);
}
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 08:03 AM
Hi,
Move the below loop before the "var caller = g_form.getReference('first_user_name', doAlert); " line
if(newValue==''){
g_form.clearValue('user_id');
}