- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 12:13 PM
We've used http://www.servicenowguru.com/system-ui/ui-macros/add-me-ui-macro-user-group-fields/ to add the "Add Me" UI macro to the Assigned to field on task table records (Incident, Problem, Change, Catalog Task, etc.) to give people a quick way of assigning the ticket to themselves.
Previously we leveraged a client script to hide the macro from the form when the record is inactive.
To align with best practice, we are trying to retire any client scripts using DOM manipulation and update the macro.
I've attempted to tweak the macro to only work when the record is active.
The challenge is that in order for this version to work, we need to include the Active field on the form itself.
Preference is not to have the Active field visible on the form.
Is there another way we can achieve this without adding Active to the form?
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="add_me_${ref}"/>
<a id="${jvar_n}" onclick="addMe('${ref}')">
<img border="0" src="images/icons/user_obj.gifx" title="${gs.getMessage('Add me')}" alt="${gs.getMessage('Add me')}"/>
</a>
<g2:evaluate var="jvar_groups" expression="gs.getUser().getMyGroups()" />
<script>
function addMe(reference) {
//Hide any field messages
g_form.hideFieldMsg('assigned_to', true);
//Check to see if the user is a member of selected group
var aGrp = g_form.getValue('assignment_group');
var myGroups = '$[jvar_groups]';
var active = g_form.getValue('active');
if(active === 'true' $[AMP]$[AMP] aGrp $[AMP]$[AMP] myGroups.indexOf(aGrp) > -1){
//Get the user reference field and populate the current user
var s = reference.split('.');
var referenceField = s[1];
g_form.setValue(referenceField, '$[gs.getUserID()]');
} else if(active !== 'true'){
//Display a field error message
g_form.showFieldMsg('assigned_to','Unable to update Assigned to. Record is no longer active.','error');
}
else{
//Display a field error message
g_form.showFieldMsg('assigned_to','You are not a member of the current assignment group. Please select one of your groups and try again.','error');
}
}
</script>
</j:jelly>
Thanks in advance.
Ron
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 09:22 PM
@rlehmann I have updated the code to remove the message and added a info message to check what value we are getting for active field from script include.
UI Macro:
Let me know if there is any issue.
If everything works fine then remove the info message from code.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 11:35 AM
Doesn't seem to be working correctly for us.
The Add Me button is hidden on all records and the Field message is appearing on all active and inactive records.
I'm also seeing this Field message on all inactive records in my PDI.
The field message should only appear if the UI Macro button is clicked on an inactive record, which technically is no longer possible with the button now hidden.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 04:56 PM - edited 06-07-2023 05:27 PM
@rlehmann it is working perfectly fine for me. I tested it in my pdi. Please send the code you added. And which table you are trying this on?
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 09:22 PM
@rlehmann I have updated the code to remove the message and added a info message to check what value we are getting for active field from script include.
UI Macro:
Let me know if there is any issue.
If everything works fine then remove the info message from code.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 06:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 07:52 AM
@jaheerhattiwale would you be so kind as to look at the updated code for the UI macro and the associated script include to see what I may have coded incorrectly?
Thanks for your assistance.