Insert comments by system in Busines rules
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 04:43 PM
Hello, I have a Business rules in the approvals table, where I check whether the approving user has delegated their functions to someone else, if this is true they insert a comment, however I would like this comment to be made by the system and not by logged in user,
Here is my script
(function executeRule(current, previous /*null when async*/ ) {
// Check if the approving user has delegated their functions
var delegateGR = new GlideRecord('sys_user_delegate');
//delegateGR.addEncodedQuery('user=' + current.approver + '^endsBETWEENjavascript:gs.beginningOfToday()@javascript:gs.endOfNextMonth()');
delegateGR.addQuery('user', current.approver);
delegateGR.addQuery('approvals','true');
delegateGR.addQuery('ends', '>', current.sys_created_on);
delegateGR.query();
if (delegateGR.next()) {
// Get the name of the user to whom the function was delegated
var delegateTo = delegateGR.delegate.getDisplayValue();
var delegate = delegateGR.user.getDisplayValue();
// Get the approval records of the approving user with requested status
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('approver', current.approver);
approvalGR.addQuery('state', 'requested');
approvalGR.query();
// Add a comment to each approval record
while (approvalGR.next()) {
var message = gs.getMessage('delegated their approval functions to:');
approvalGR.comments = delegate + ' ' + message + ' ' + delegateTo;
approvalGR.update();
}
}
})(current, previous);
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 05:04 PM
You can use setJournalEntry to define the comment and who wrote the comment.
It's something like;
approvalGr.comments.setJournalEntry('message','abel_tutor');