- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 02:11 PM
Hello,
I have been assigned with updating the change request process to automatically transfer comments from the approval table to the change record whenever a comment is present. I'm relatively new to working with the change request module, so I'm reaching out to the community for guidance and support.
Here's my progress thus far. Thank you
Condition:
current.comments.changes() && (!current.sysapproval.isNil()) && current.sysapproval.sys_class_name == 'change_request'
Script:
function onBefore(current, previous) {
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
if (gr.next())
{
gr.work_notes = "The following comments have been added by the approver " + current.approver.name + " for this Change request:\n " + current.comments;
gr.update();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 02:45 PM
Hi @Keang
Can you try the below script:
business rule : before, insert/update
script:
(function executeRule(current, previous /*null when async*/ ) {
var changerequest = new GlideRecord('change_request');
changerequest.addQuery('sys_id', current.document_id);
changerequest.query();
if (changerequest.next()) {
changerequest.comments = changerequest.comments + "\n" + current.comments.getJournalEntry(-1); // Appending the latest comment
changerequest.update();
}
})(current, previous);
It is working in my PDI.
Thanks and regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 04:05 PM
Hi @Keang
you can try the below code
(function executeRule(current, previous /*null when async*/ ) {
if (!current.sysapproval.isNil() && current.sysapproval.sys_class_name == 'change_request') {
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.sysapproval.sys_id)) {
var changeType = changeRequest.type.getDisplayValue(); // Assuming 'type' is the field holding change type
if (changeType.toLowerCase() === 'normal') {
changeRequest.comments = changeRequest.comments + "\n" + current.comments.getJournalEntry(-1);
changeRequest.update();
}
}
}
})(current, previous);
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 02:45 PM
Hi @Keang
Can you try the below script:
business rule : before, insert/update
script:
(function executeRule(current, previous /*null when async*/ ) {
var changerequest = new GlideRecord('change_request');
changerequest.addQuery('sys_id', current.document_id);
changerequest.query();
if (changerequest.next()) {
changerequest.comments = changerequest.comments + "\n" + current.comments.getJournalEntry(-1); // Appending the latest comment
changerequest.update();
}
})(current, previous);
It is working in my PDI.
Thanks and regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 03:07 PM
Hello @SAI VENKATESH
Thank you for helping. Your suggestion code works. Is it possible to trigger the business rule only on
Type: "Normal" not Emergency Change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 04:05 PM
Hi @Keang
you can try the below code
(function executeRule(current, previous /*null when async*/ ) {
if (!current.sysapproval.isNil() && current.sysapproval.sys_class_name == 'change_request') {
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.sysapproval.sys_id)) {
var changeType = changeRequest.type.getDisplayValue(); // Assuming 'type' is the field holding change type
if (changeType.toLowerCase() === 'normal') {
changeRequest.comments = changeRequest.comments + "\n" + current.comments.getJournalEntry(-1);
changeRequest.update();
}
}
}
})(current, previous);
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 04:30 PM
Thank you so much @SAI VENKATESH . It is working great .