The CreatorCon Call for Content is officially open! Get started here.

Compare Login User with the Assigned To reference field in the UI Action button

BKSharma
Tera Contributor

Hi,

I'm working on some UI Action. In the RITM form I've a UI Action button.

My requirement is to when a user click on that button, I need to validate, if the logged in user is the user mentioned in the assigned_to field or anyother user.

How I can validate this?

1 ACCEPTED SOLUTION

YaswanthKurre
Tera Guru

Hi @BKSharma ,

 

You can use this script in UI action field.

 

var assignedTo = g_form.getValue('assigned_to');
var loggedInUser = g_user.userID;

if (assignedTo === loggedInUser) {
    alert("You are the assigned user.");
} else {
    alert("You are not the assigned user.");
}

 

Mark this as helpful and correct if this solves your question.

 

Thanks,

Yaswanth.

View solution in original post

12 REPLIES 12

YaswanthKurre
Tera Guru

Hi @BKSharma ,

 

You can use this script in UI action field.

 

var assignedTo = g_form.getValue('assigned_to');
var loggedInUser = g_user.userID;

if (assignedTo === loggedInUser) {
    alert("You are the assigned user.");
} else {
    alert("You are not the assigned user.");
}

 

Mark this as helpful and correct if this solves your question.

 

Thanks,

Yaswanth.

Thank you @YaswanthKurre ,

It worked fine. 

Hi @YaswanthKurre ,

I just need one more validation here, How I can check the logged In User is a part of same assignment group or not in the same UI action button.

Ankur Bawiskar
Tera Patron
Tera Patron

@BKSharma 

your UI action is client side or server side?

Also why not show that UI action only to the user present in Assigned to field

You can add condition in UI action condition field

current.assigned_to == gs.getUserID()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader