The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to write a comment to a journal field from a background script?

Laurie Marlowe1
Kilo Sage

Hello,

We have a text field, and we want to copy the contents of the text field to a new journal input field.   We have a journal list field to display the contents of the journal input field. We want a separate journal input and journal list field as the information entered is sensitive.

Old text field: u_ncpi_information

New journal input field:   u_ncpi_information_journal

New journal list field:   u_ncpi_information_list

I created a background script to do this, however, the journal list does not show the update.   I tried several different code variations, but no luck.

//move data from 'old' NCPI field (u_ncpi_information) to new NCPI Information Journal field

var count = 0;

var inc = new GlideRecord('incident');

inc.setLimit(1);

inc.addQuery('u_ncpi_information','!=','');

inc.query();

while(inc.next()) {

inc.u_ncpi_information_journal = inc.u_ncpi_information;

inc.setWorkflow(false);

gs.print(inc.number);

count = count + 1;

inc.update();

}

gs.print(count);

Any ideas?

Thank you,

Laurie

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Laurie,



Try


inc['u_ncpi_information_journal'].setJournalEntry(inc.u_ncpi_information); instead of inc.u_ncpi_information_journal = inc.u_ncpi_information;


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Laurie,



Try


inc['u_ncpi_information_journal'].setJournalEntry(inc.u_ncpi_information); instead of inc.u_ncpi_information_journal = inc.u_ncpi_information;


Thanks, Pradeep!  


Hi Pradeep,



Question - what do the "[" and "]" symbols mean in the code you gave me?



Thanks,



Laurie


Hello Laurie,



You can write inc['u_ncpi_information_journal'] OR inc.u_ncpi_information_journal //Here u_ncpi_information_journal is the field column name