- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @Ankur Bawiskar ,
I just tried below but it's not getting validated -
My requirement is, if the logged in user is the Assigned To user, then Additional Comments (comments) is mandatory else, both Worknote (work_note) and Additional Comments (comments) are mandatory.
This needs to be done through UI Action only. As there is a dedicated UI action button for the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
update as this
function checkMandatory() {
if (g_form.getValue('state') == '5' && (g_form.getValue('assigned_to') == g_user.userID)) {
if (g_form.getValue('comments') == '') {
g_form.hideFieldMsg('comments');
g_form.setMandatory('comments', true);
alert('Additional Comments are mandatory when placing the requested item into Work in Progress.');
return false;
}
} else
if ((g_form.getValue('work_notes') == '') && (g_form.getValue('comments') == '')) {
g_form.hideFieldMsg('work_notes');
g_form.hideFieldMsg('comments');
g_form.setMandatory('work_notes', true);
g_form.setMandatory('comments', true);
alert('Work Notes and Additional Comments are mandatory when placing the requested item into Work in Progress.');
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'requested_item_work_in_progress');
}
if (typeof window == 'undefined')
serverWIP();
function serverWIP() {
current.state = 2;
current.update();
action.setRedirectURL(current);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Thank you for marking my response as helpful.
Please mark my response as correct if that worked for you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I just need one more validation here in the else part of the code - How I can check the logged In User is a part of same assignment group or not in the same UI action button?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can use display business rule and store g_scratchpad variable
that variable will hold and check if logged in user is part of same group or not
then access it in client side code of UI action.
I hope you are aware on how to create display BR and use scratchpad variable.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader