only display ui action if current user is the requested for user

sigmachiuta
Kilo Guru

I am trying to create a UI action condition that the user that should see the UI action is the person that has requested the item.   Would this work in the condition?

current.requested_for == gs.getUser().    

1 ACCEPTED SOLUTION

As you seem to be trying to combine client-side and server-side methods in a single script, you need to use a special technique that is very well explained by Mark Stanger in the following blog post:


Client & Server Code in One UI Action - ServiceNow Guru


View solution in original post

6 REPLIES 6

Deepak Negi
Mega Sage
Mega Sage

Try



current.requested_for == gs.getUserID().  


Slava Savitsky
Giga Sage

It all depends on where you are trying to place this button. The reference to the requestor comes from the Request (REQ) level. Thus if you want to have the button on REQ form, use this code:



current.requested_for == gs.getUserID();



If you are trying to set it up on Requested Item (RITM) form, dot-walk to the parent request record like this:



current.request.requested_for == gs.getUserID();


ok so here is my UI action that should cancel the Request Item but when i click the cancel button nothing happens.




function checkCancel(){


  if(g_form.getValue('u_cancel_reason') == ''){


  alert('Please provide a Cancel reason.');


  g_form.setMandatory('u_cancel_reason',true);


  } else {


  gs.addInfoMessage('The current item request has been cancelled.');


  current.state = '4';


  current.stage = 'Request Cancelled';



  //get workflow helper


  var workflow = new Workflow();


  //cancel all the workflows, where current is a task record with a workflow context


  workflow.cancel(current);


  gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));


  current.update();




  }


}


}


As you seem to be trying to combine client-side and server-side methods in a single script, you need to use a special technique that is very well explained by Mark Stanger in the following blog post:


Client & Server Code in One UI Action - ServiceNow Guru