How to split work notes value?

Jitendra Diwak1
Kilo Sage

I have a work notes field on the incident table so I have to split it and store in the array and I can get the whole comment value in a particular array's index. I am doing this in the business rule

(function executeRule(current, previous /*null when async*/) {
    var notes = current.work_notes.getJournalEntry(-1);
    gs.addInfoMessage(notes);
    var spl = [];
    spl = notes.split('(Work notes)');
    gs.addInfoMessage(spl[0]);
    gs.addInfoMessage(spl[1]);
    gs.addInfoMessage(spl[2]);
    gs.addInfoMessage(spl[3]);

})(current, previous);

I get the output like this

04/02/2019 01:59:37 PM - System Administrator

Hari 04/02/2019 01:52:19 PM - System Administrator

Jitendra 04/02/2019 01:51:42 PM - System Administrator

Jitendra 04/02/2019 01:50:56 PM - System Administrator
 
My requirement is:
04/02/2019 01:59:37 PM - System Administrator Hari 
 
Jitendra 04/02/2019 01:52:19 PM - System Administrator
 
Jitendra 04/02/2019 01:52:19 PM - System Administrator
 
I dont have to use OOTB '\n\n' functionality
 

 

Please accept my solution if it works for and thumps up.
4 REPLIES 4

shanecarroll
Mega Expert

Hi,

Can you clarify what the requirement is here?

Jitendra Diwak1
Kilo Sage

I have a work notes field on an incident table so "var notes = current.work_notes.getJournalEntry(-1);" this lines bring all comments in a single string so I have separate all work notes activity in separate array index.

If I type arr[0];

o/p: 04/02/2019 01:59:37 PM - System Administrator Hari 

 

If I type arr[1];

o/p: 04/02/2019 02:01:37 PM - System Administrator I am working on it

Please accept my solution if it works for and thumps up.

A-N
Tera Expert

Hi,

Try this and let me know if it works !!!

(function executeRule(current, previous /*null when async*/) {

 var notes = current.work_notes.getJournalEntry(-1);
    gs.addInfoMessage(notes);

    var spl = [];
	spl = notes.replace(/\(Work notes\)/g,'').split("\n\n");
    gs.addInfoMessage(spl[0]);
    gs.addInfoMessage(spl[1]);
    gs.addInfoMessage(spl[2]);
    gs.addInfoMessage(spl[3]);
	
	
	
})(current, previous);

Do not have to use \n\n OOTB functionality

Please accept my solution if it works for and thumps up.