UI action wont work as list context menu

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I have a UI action which at the moment is a form button and works as intended. Then people asked me if I they couldnt have it like context menu in the incident list as well. It sounded like a good idea, but I thought I just needed to click the   "list context menu" and it should work. But when I now click on it in the list nothing happens.

Im pretty new to ServiceNow but I cant see anything in any log either that could point that this is the problem. We have a ACL on incident state and operation list_edit but I turned active to false since I guess this counts as a list edit.

Here is the ui action and any idea would be appreciated

fel ui action Assigntome.JPG

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

The reason this won't work in a list UI action is that 'g_from' isn't available from lists, just forms.   Any 'g_form' call will die in a list UI action.   Unless you want to create a complex UI page and glide dialog, there's no way to make this work in exactly the same way from a list.


View solution in original post

4 REPLIES 4

Mark Stanger
Giga Sage

The reason this won't work in a list UI action is that 'g_from' isn't available from lists, just forms.   Any 'g_form' call will die in a list UI action.   Unless you want to create a complex UI page and glide dialog, there's no way to make this work in exactly the same way from a list.


Completely agree with Mark - try to get information on WiKi how to work with lists (g_list)


Thanks,



That explains it 😃 Abit annoyed that I couldnt find anything in any log that it didnt work as intended, but perhaps something is just what is it.



Im just wondering if it is easy to explain (I aint a expert developer) But the code. If I was to write the script from scratch I would only have done something like:



function assign_to_me(){


      current.assigned_to = gs.getUserID();


  if (current.sys_class_name == 'incident' || current.sys_class_name == 'problem')


  current.state = 10;


  else if (current.sys_class_name == 'change_request' || current.sys_class_name == 'sc_req_item')


  current.state = 2;


      current.update();


      action.setRedirectURL(current);


}



Why all the extra code?


Generally the type of code in your current UI action is used to perform some sort or form validation or require mandatory fields to be filled out only at the time that specific UI action is clicked and a form is submitted.   That's why all of the 'g_form' calls, because that type of thing happens with a form, not a list.



You're right though, in reviewing your screenshot I can see that none of that structure is necessary.   All it does is set the values to the record.   That can all be done in a standard, server-side UI action that should work equally as well in a list as in a form.



To make this work you'll want to do the following...



1) Uncheck the 'Client' checkbox and clear the 'onClick' field.   Those aren't necessary at all in this case.


2)   Adjust your code to look like this...



//Call the function here...


assign_to_me();



function assign_to_me(){


      current.assigned_to = gs.getUserID();


      if (current.sys_class_name == 'incident' || current.sys_class_name == 'problem')


              current.state = 10;


      else if (current.sys_class_name == 'change_request' || current.sys_class_name == 'sc_req_item')


              current.state = 2;



      current.update();


      action.setRedirectURL(current);


}



The last line (the redirect one) is the one that you might want to consider removing to make this work well in both places.   It redirects the user to the current record (basically reloading the form when you're looking at a single record).   In a list scenario, the code is run against every item in the list so it would set that for every record and then redirect you to the last record it updated (which you probably don't want).