The CreatorCon Call for Content is officially open! Get started here.

Send worknotes using REST API

Madhavi2
Tera Contributor

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

 

 

4 REPLIES 4

SumanthDosapati
Mega Sage
Mega Sage

Hi, 

Do you want to send the last worknote with every space as new line?

 

Regards,

Sumanth

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.

 

Pavankumar_1
Mega Patron

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

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Hi Pavan,

Sorry it is not working.