Journal_input not saving data through script

ajitchandragiri
Giga Expert

Hi all,

we have a custom table with few fields. Requirement is to the change one of the String fields (say Review comment u_review_comments) to a Journal input field to track changes to this field. I created a new Journal_input field. Its working fine. Now, i need to copy the values of Review Comment string field (max length=1000) to this new field u_review_comment . i wrote the following script and ran it in background scripts. Its not working. Any input is appreciated. I am in Helsinki patch 11.

var csi = new GlideRecord('XXX');

//csi.addQuery('u_number', 'CSI0001043');

csi.query();

while(csi.next()){

gs.print('count ' + csi.getRowCount());

var comment = csi.u_review_comments;

gs.print('comment ' + comment);

csi.u_review_comment = comment;

csi.update();

}

the rowcount and comment variable have data show data, the value is just not coming over to journal field meaning its not showing in activity. If i just pass a string like csi.u_review_comment = 'testing'; it works.

1 ACCEPTED SOLUTION

sethivarun
Kilo Guru

hi Ajit,


use the following :



var csi = new GlideRecord('XXX');


//csi.addQuery('u_number', 'CSI0001043');


csi.query();


while(csi.next()){


gs.print('count ' + csi.getRowCount());


var comment = csi.u_review_comments;


gs.print('comment ' + comment);


csi.u_review_comment.setJournalEntry(comments);


csi.update();


}



i have replaced csi.u_review_comment = comment; with csi.u_review_comment.setJournalEntry(comments);nts);




Please mark it as correct if helpful



Pk


View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Ajit,



Change line from var comment = csi.u_review_comments;to var comment = csi.u_review_comments.getJournalEntry(-1);


Using Journal Fields - ServiceNow Wiki


sorry i thought i had already replied to your comment Pradeep. getJournalEntry(-1) did not work. its gives me 'undefined'. Original Review Comments (u_review_comments) is a string field. i did not knw about the JournalEntry functions. i checked it and it works only for Journal fields. since review comments is a string it did not work.


You are right Ajit. It will only work for Journal entry fields. I thought the field you are referring to is a journal field.


sethivarun
Kilo Guru

hi Ajit,


use the following :



var csi = new GlideRecord('XXX');


//csi.addQuery('u_number', 'CSI0001043');


csi.query();


while(csi.next()){


gs.print('count ' + csi.getRowCount());


var comment = csi.u_review_comments;


gs.print('comment ' + comment);


csi.u_review_comment.setJournalEntry(comments);


csi.update();


}



i have replaced csi.u_review_comment = comment; with csi.u_review_comment.setJournalEntry(comments);nts);




Please mark it as correct if helpful



Pk