Change Request form

roomawakar
Tera Contributor

Hi All,

 

There is requirement where i need to add a field of List type called as 'Peer Review' on the change request form.

 

I have created the field and need to put the condition on that field that the Requestor should be able to choose one or more people from the Assignment group as their Peer Reviewers and put a validation to restrict the Requester and Assigned to, to approve the record.

 

I am not able to understand how to put that condition so that the members of the assignment group only should be visible in that field and it should exclude Requester and Assigned to from that list of users.

 

Can someone please help on this?

4 REPLIES 4

Mannam Praveen
Tera Expert

Create busines rule 

 

(function executeRule(current, previous /*null when async*/) {
var assignmentGroup = current.assignment_group; // Replace with your field name
var peerReviewers = current.peer_reviewers; // Replace with your field name

if (peerReviewers) {
var groupMembers = new GlideRecord('sys_user_grmember');
groupMembers.addQuery('group', assignmentGroup);
groupMembers.query();

var validPeerReviewers = [];
while (groupMembers.next()) {
validPeerReviewers.push(groupMembers.user.sys_id + '');
}

var isValid = true;
peerReviewers.split(',').forEach(function(peer) {
if (validPeerReviewers.indexOf(peer) === -1) {
isValid = false;
}
});

if (!isValid) {
gs.addErrorMessage('Peer Reviewers must be members of the Assignment Group.');
current.peer_reviewers = ''; // Clear the invalid selection
}
}
})(current, previous);

Amit Verma
Kilo Patron
Kilo Patron

Hi @roomawakar 

 

Make use of below Advanced Reference Qualifier for your List Collector field as shown below :

 

javascript:'sys_id!='+current.requested_by+'^ sys_id!='+current.assigned_to;

 

AmitVerma_0-1724672167210.png

 

Output :

 

In the below change, the requestor is System Administrator and Assigned To is David Loo :

 

AmitVerma_1-1724672201253.png

 

When I try to get the above users in the list collector reference, below is the output :

AmitVerma_2-1724672287919.png

AmitVerma_3-1724672333121.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

@Amit Verma Thanks for the solution but here I need all the members of the current assignment group which has been selected on the Change request except the requester and the assigned to.

@roomawakar 

 

In that case, you can refer below posts to setup a Script Include and call it from reference qualifier. In the Script Include, you can also keep the logic to get rid of the requestor and assigned to user from the output.

https://www.servicenow.com/community/developer-forum/my-query-is-populate-the-list-of-group-members-...

https://www.servicenow.com/community/itsm-forum/need-to-populate-assignment-group-members-in-list-co...

https://www.servicenow.com/community/developer-forum/display-members-of-assignment-group-in-form-var...

 


Please mark this response as correct and helpful if it assisted you with your question.