- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 11:30 AM
Hey everyone,
I have need for comments from task to follow over to the next task in workflows. I have searched and found a post that said it has a solution but it is not working for me, wondering if anyone has any advice or what I am doing wrong. I created a business rule with 'after' update and conditions are work notes changes and state is closed complete. Below is the script but it is not working for me. Any advice would be really helpful! Here is the script what am I doing wrong?
task.work_notes=pullComments();
function pullComments(){
var comments=[];
var gr= new GlideRecord("sc_task");
gr.addQuery("request_item",current.getValue("sys_id"));
//order by sys_created_on and limit to one record
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
while(gr.next()){
task.short_description = gr.short_description;
task.description = gr.description;
var wn = gr.work_notes.getJournalEntry(-1);
var regex= new RegExp('\n');
var a = wn.search(regex);
wn = wn.substring(a+1, wn.length);
comments.push(wn);
}
gs.log("From workflow final return "+comments.join());
return comments.join();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 06:09 PM
More string manipulation technics. This should leave just the name and work note, though you might have 2 names for every entry given the first Notes Example above. If that's still the case and you can't find what is adding the 'System' you can try to add a replace for 'System (Work note)s' before the existing one. As a bonus, this approach will (theoretically) still work on 2100-01-01.
(function onBefore(current, previous) {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addInactiveQuery();
gr.orderByDesc('number');
gr.query();
if (gr.next()) {
var wnArr = [];
var wn = gr.work_notes.getJournalEntry(-1).split('\n');
for (var i = 0; i < wn.length; i++) {
wn[i] = wn[i].replace('(Work notes)', '');
var index = wn[i].indexOf(' - ');
if (index > 0) {
index += 3;
}
wnArr.push(wn[i].substring(index));
}
current.work_notes = wnArr.join('\n');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 04:48 AM
Excellent it will still work in 76 years 😆, this looks good but yea it still is populating system over the name. How would I replace system work notes, apologies I am still pretty new to scripting, is there a way we could replace system with glideDateTime of the entry? I tried to just add system in the line there but no affect. Thanks again Brad!
wn[i] = wn[i].replace('system(Work notes)', '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 05:07 AM
The replace method is space - and case-sensitive, so it would be
wn[i] = wn[i].replace('System (Work notes)', '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 05:19 AM
Oh, ok that worked!! Thank you so much for all your help and patience, would have probably been stuck on this for a while if it wasn't for you! I really appreciate you sharing your time and knowledge with me.
Thank you,
Jonathan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 05:27 AM
You are welcome. I'm happy to help.
Connect with me https://www.linkedin.com/in/brad-bowman-321b1567/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2024 11:22 AM