- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 11:49 PM
Hi Team,
I am converting task to incident in which I am copying work notes from task to incident
I have written ss rule on incident with below code
var sTask = new GlideRecord("sc_task");
if (sTask.get(current.parent)) {
current.work_notes = sTask.work_notes.getJournalEntry(1);
current.update();
}
But I am getting only current work notes I want whole worknotes I tried also with = "current.work_notes = sTask.work_notes" but this is not working.
Please help me here how can I copying whole worknotes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 12:17 AM
Hi @lucky24
Use getJournalEntry(-1) instead of getJournalEntry(1).
https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideElementScope...
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 12:17 AM
Hi @lucky24
Use getJournalEntry(-1) instead of getJournalEntry(1).
https://developer.servicenow.com/dev.do#!/reference/api/utah/server/no-namespace/c_GlideElementScope...
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 12:56 AM
Thanks Niklas
Above suggestion is working for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 12:24 AM
Hi @lucky24 ,
Hope you are doing great.
Below is reference script to copy entire worknotes:
// Retrieve the parent task
var sTask = new GlideRecord("sc_task");
if (sTask.get(current.parent)) {
// Copy all work notes from the task to the incident
var workNotes = '';
var journal = new GlideRecord("sys_journal_field");
journal.addQuery("element_id", sTask.sys_id);
journal.addQuery("element", "comments");
journal.query();
while (journal.next()) {
workNotes += journal.value + '\n';
}
// Set the copied work notes on the incident
current.work_notes = workNotes;
current.update();
}
Regards,
Riya Verma