Pop-up window with Menu

garyopela
ServiceNow Employee
ServiceNow Employee

Okay, so I need to create a client script that runs on change. This would run on the Change Request and auto-populate a field on change from the CMDB.

Right now i just reference the field as the field can only have one group in it, and then the group is pulled in as an approval group. Works great right now.

The problem now is that I have some apps that might need multiple groups in the group field on the CI, and then the customer on the change would choose the particular group for that change. So basically i've created a glide-list on the CI that can contain an array of groups. Now what i'm trying to do is write a client script on the change that would run when the CI on the change was changed. The script will set the group field on the change automatically if there is only one group in the glide_list (i already have this figured out).

Now the hard part that i've yet to figure out, if there is more than one group in this field on the CI, i want to present a pop-up to the customer where they can have a menu and choose exactly and only one of the results from the menu, which would be populated from the fields in the glide_list on the CI. I have most of this figured out, the part I'm missing though is building the javascript pop-up and the menu and setting values to the menu.

Does anyone have any suggestions here?

8 REPLIES 8

gaidem
ServiceNow Employee
ServiceNow Employee

This also fails, just info that makes me feel like you need to look at another option:

Do a simple onChange script:



$('lookup.change_request.u_bus_approver').click();


This is basically invoking a click on the reference magnifying glass.


andrew_kincaid
ServiceNow Employee
ServiceNow Employee

As much as I dislike using setTimeout because it's just not an accurate way of sequencing events, in this case, it seems like a decent solution. It appears that IE is killing the second window because it opens "too quickly" so it assumes it's a bad thing. If you wrap your code in a setTimeout and use a 200ms delay, IE won't kill the second popup window, at least it didn't in my testing. Around 150-160ms, it was iffy if IE would close it or not. 200ms seems like a safe delay.



setTimeout(function () {


      var list = g_form.getReference('cmdb_ci').u_bus_group.toString();


      var array = list.split(",");


      if (array.length > 1) {


              var ret = "sys_idIN" + g_form.getReference('cmdb_ci').u_bus_group;


              reflistOpen('change_request.u_bus_approver', 'not', 'sys_user_group', null, null, null, ret);


      } else {


              g_form.setValue('u_bus_approver', g_form.getReference('cmdb_ci').u_bus_group);


      }


}, 200);



Let us know if that works or not in your environment.


I would also sugest reducing the number of getReferences here. Maybe look at doing an indexOf(',') instead and use that once defined getReference.


Set Timeout worked like a charm. Thanks for all the help guys!