How to conditionally set the choice value on a "List" Type field that references the sys_user table.

michaelcory
Giga Expert

I have a "selector" field on a form that references the sys_user table.   It is a "List" type field so uses the little padlock icon to open the selector and select multiple values from the user table.   I have 3 choices in another select box field.   If "Yes - IS Global Only" is selected it displays the selector field and allows the requestor to select a user from the table.   I need to auto-set a user in the selector if the option of "Yes - IS Global Only" is selected from the select box field.   I used the following client script but it's not working:

function onChange() {

  var SendNew = g_form.getValue('u_send_notification');//Select box field choices

  if (SendNew == 'Yes - IS Global Only'){ //'Yes - IS Global Only' is one of 3 options

  g_form.setValue('u_notify_user', 'IS Global');//Set the User in the selector box to IS Global

    }

}

Any input would be appreciated.   Thanks,

1 ACCEPTED SOLUTION

Hey Mike,



That should be fine. I am glad I was helpful to you. I am pasting the script and final code here.


Script :


function onChange() {


var SendNew = g_form.getValue('u_send_notification');


if (SendNew == "Yes IS Global" || SendNew == "Yes"){


g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//IS Global sys_id


}


if (SendNew == "No"){


g_form.clearValue('u_notify_user')


}


}


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)


View solution in original post

14 REPLIES 14

You mean you got blank alert for variable sendNew?


Yes, sorry that is correct.   The blank alert was for sendNew


So basically it will never enter the if loop as per the condition then. Just remove if condition and try to set the value to check if the value for who to notify is set or not.


Interesting....the onLoad function (script below) sets the default to IS Global, so that piece works.   Anyway to set the condition that you know of?



function onLoad() {


//var SendNew = g_form.getValue('u_send_notification');//Select box field choices


//alert(SendNew); //make sure that the choice value is populated correctly


  //if (SendNew == "Yes - IS Global Only"){ //'Yes - IS Global Only' is one of 3 options


//alert('in loop');


  g_form.setValue('u_notify_user','08c5f8b42bfbb1007e94559bf8da155b');//Replace IS Global with the sys_id of the record


}



onLoad set to IS Global.jpg


So what is the exact if condition you are looking for?