Not able to insert into Journal field through Glide Record in Service Catalog

vallamreddyvenu
Giga Contributor

Hi,

We are creating a service catalog in which we have a variable named comments that is mapped to "Journal Input" type. In the catalog client script we need to insert into the table using GlideRecord. But when i assign a value to the journal field, the script is not working. If i comment the line assigning value to Journal field, the script is working.

Below is the script.

var gr = new GlideRecord('u_requests');

  gr.initialize();

  gr.short_description = "Test Title";

  gr.description = "Test Description";

  gr.u_caller_id = "RequestedFor";

  gr.cmdb_ci = "Environment";

  gr.u_request_start_date = "05/16/2017";

  gr.comments= "Test Comments";

  //gr[comments].setJournalEntry(Comments);

  gr.u_product = "Product Name";

  gr.insert();

Can somebody please check my script above and correct the mistake that i am doing?

Thanks,

Venu

13 REPLIES 13

Siddartha Gudim
Tera Guru

Hi Venugopal,




The script is good and has no error except the commented part. Generally any entry to journal field through script follows the same notation as of other field types such as a string field.



Please mark correct or helpful based on the impact of the response.



Regards,


Siddhartha Gudimalla


Community Alums
Not applicable

With respect, this is incorrect. There is a function in the GlideElement API specifically for this purpose:



http://wiki.servicenow.com/index.php?title=GlideElement#setJournalEntry.28Object.2C_String.29


Community Alums
Not applicable

> //gr[comments].setJournalEntry(Comments);




This line would work, but your syntax is incorrect. The argument in the parenthesis needs to either be a string surrounded by quotes, or an object. Either of these should work:



gr[comments].setJournalEntry('test 1234');



or



gr[comments].setJournalEntry(gr.comments);


Hi Andrew,


Thanks for your reply.



Infact, the Comments is a string object which has got some string value into it. But still it didn't work.



Thanks,


Venu


Community Alums
Not applicable

Where in your code is the value of the object set? It wasn't in your code above. That might be the problem.