Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Determine Which UI Action Control Was Used

Matthew Glenn
Kilo Sage

Hello all,

I have a server-side UI Action that has both the 'Form Context Menu' and the 'List Choice' controls checked.

Is there an easy way I can detect which one of these controls was used?

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Matthew,



You can use getActionName at client side to determine action name of UI action.


function onSubmit() {


    var action = g_form.getActionName();


    alert('You pressed ' + action);


}


http://wiki.servicenow.com/index.php?title=Getting_a_User_Object#gsc.tab=0


That would tell you the action name, but since this is available from both the form and the list, the action name will be the same. I was thinking there may be a g_list object or method that you could check. If it is undefined, you're on the form.



Maybe the inverse for g_form?



It's worth a try.



GlideForm (g form) - ServiceNow Wiki


You are correct Chuck . I got confused with the question. My bad.


There is a g_list object which is available from a UI action when it's called from a list. Though it's only available client side so you will have to make sure it's a client UI action, do your check, then call the appropriate server code if needed.



GlideList2 (g list) - ServiceNow Wiki



Something like this inside your UI action should do the trick:



function myOnClickFunction() {


  if (typeof g_list !== 'undefined') {


      alert('Called from a list!');


  } else {


      alert('Called from a form!');


  }


}