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

Checking the user who added the latest additional comment on Incident.

Pablo H
Tera Contributor

Hello all,

I want to create before update BR on incident when a new comment is added checks if user belongs to the Assignment group, if yes then set the field value. I come up with the below script but its not working. Any help? Thank you

 

Condition: current.comments.changes()

(function executeRule(current, previous /*null when async*/ ) {

    var recGR = new GlideRecord('sys_journal_field');
    recGR.addQuery('element_id', current.sys_id);
    recGR.query();
    if (recGR.next()) {
        if (gs.getUser().isMemberOf('assignment_group')) {
            current.setValue('u_last_comment_by', 'resolver');
        } else {
            current.setValue('u_last_comment_by', 'end_user');
        }
    }
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

(function executeRule(current, previous /*null when async*/ ) {

	if (gs.getUser().isMemberOf(current.assignment_group.toString())) {
		current.setValue('u_last_comment_by', 'resolver');
	} else {
		current.setValue('u_last_comment_by', 'end_user');
	}


})(current, previous);

Regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

(function executeRule(current, previous /*null when async*/ ) {

	if (gs.getUser().isMemberOf(current.assignment_group.toString())) {
		current.setValue('u_last_comment_by', 'resolver');
	} else {
		current.setValue('u_last_comment_by', 'end_user');
	}


})(current, previous);

Regards
Ankur

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

Rahul Bhor
Tera Contributor

Any special case you are querying the sys_journal_field table? if yes please explain or you can modify your code as below,

(function executeRule(current, previous /*null when async*/ ) {

    if (gs.getUser().isMemberOf(current.assignment_group.toString())) {
        current.setValue('u_last_comment_by', 'resolver');
    } else {
        current.setValue('u_last_comment_by', 'end_user');
    }

})(current, previous);