Send worknotes using REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 07:59 AM
Hi,
I am passing the worknotes from servicenow to third party system. I observed worknotes are coming with \r\n.
So I am trying with below script.
var c=current.work_notes.getJournalEntry(1).toString();
var e =c.replace(/\r\n|\r|\n|\\\\\\/g, '\n ');
var b = e.replaceAll('\n',' ');
r.setStringParameter('work_notes',b);
This is the output I am receiving in log.
notes2022-07-12 02:15:49 - Guest (Work notes) test ticket1 2 3 4 5
I would like send line by line
test ticket1
2
3
Please help me on this.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 08:18 AM
Hi,
Do you want to send the last worknote with every space as new line?
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 07:19 AM
Hello Sumanth,
Yes. But not every space as new line. If there is a new line in the worknotes it should come as it is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2022 09:05 AM
Hi,
Can you try below code to retrieve the output as you expected.
var c=current.work_notes.getJournalEntry(1).toString();
var e =c.replace(/[" "]/g, '\n');
r.setStringParameter('work_notes',e);
Hope it helps!!
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 07:59 AM
Hi Pavan,
Sorry it is not working.