- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Hi,
I've below 2 requirements -
1. When a RITM is moved by an 'agent' from 'Open' to 'Work In Progress', "Additional Comments" (instead of Work Notes) must be mandatory.
2. When a RITM is moved by an 'Assignment Group member (non-assignee)' from 'Open' to 'Work In Progress', both "Additional Comments" and "Work Notes" must be mandatory.
How I can achieve above 2 things.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Something like this but please enhance
I assume you are checking some agent role in your 1st point.
Script Include: It should be client callable
var RITMAgentGroupCheck = Class.create();
RITMAgentGroupCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isAgent: function() {
var userId = this.getParameter('sysparm_user_id');
// Check if user has 'agent' role
if (gs.getUser().hasRole('agent'))
return 'true';
return 'false';
},
isAssignmentGroupMemberNotAssignee: function() {
var userId = this.getParameter('sysparm_user_id');
var ritmSysId = this.getParameter('sysparm_ritm_sysid');
var ritmGR = new GlideRecord('sc_req_item');
if (!ritmGR.get(ritmSysId))
return 'false';
var assignmentGroup = ritmGR.assignment_group.toString();
var assignee = ritmGR.assigned_to.toString();
// Check if user is in assignment group but not assigned_to user
var groupMemberGr = new GlideRecord('sys_user_grmember');
groupMemberGr.addQuery('group', assignmentGroup);
groupMemberGr.addQuery('user', userId);
groupMemberGr.query();
var isMember = groupMemberGr.hasNext();
var notAssigned = (userId != assignee);
if (isMember && notAssigned) {
return 'true';
}
return 'false';
},
});
onChange client script: State field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue !== '2') // 2 = Work In Progress state, adjust as needed
return;
var ga = new GlideAjax('RITMAgentGroupCheck');
ga.addParam('sysparm_name', 'isAgent');
ga.addParam('sysparm_user_id', g_user.userID);
ga.getXMLAnswer(function(agentResponse) {
if (agentResponse === 'true') {
// Agent moving RITM: Additional Comments mandatory only
g_form.setMandatory('additional_comments', true);
g_form.setMandatory('work_notes', false);
} else {
// Check assignment group member condition
var ga2 = new GlideAjax('RITMAgentGroupCheck');
ga2.addParam('sysparm_name', 'isAssignmentGroupMemberNotAssignee');
ga2.addParam('sysparm_user_id', g_user.userID);
ga2.addParam('sysparm_ritm_sysid', g_form.getUniqueValue());
ga2.getXMLAnswer(function(memberResponse) {
if (memberResponse === 'true') {
// Assignment group member (non-assignee): Both mandatory
g_form.setMandatory('additional_comments', true);
g_form.setMandatory('work_notes', true);
} else {
// Otherwise, clear mandatory (optional)
g_form.setMandatory('additional_comments', false);
g_form.setMandatory('work_notes', false);
}
});
}
});
}
I believe I have answered your question and you can enhance it further based on your requirement and developer skills.
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
a week ago
Hi @Ankur Bawiskar
Can you please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
Hello @BKSharma
First, create a before update BR and check the current user to see if they are an agent or part of the group.
Second, within the BR, check the type. If it is an agent, mark Additional Comments as mandatory.
If they are a member of the assigned group, both fields will be mandatory.
To do this, either use a BR or a UI policy that checks the user.
With the UI policy, you can select the field and make it mandatory. With the BR, use this, for example:
g_form.setMandatory(‘comments’,true);
g_form.setMandatory(‘work_notes’,true);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
you can easily achieve this using onChange client script + GlideAjax (to check who is moving the RITM)
where are you stuck and what did you start with?
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
a week ago
Hi @Ankur Bawiskar , On Change Client Script part is ok. How I can check the who is moving the RITM and use that via Glide Ajax in the same Client Script?