Not able to insert into Journal field through Glide Record in Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 05:17 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 05:20 AM
Have you defined a Variable called Comments somewhere in code?
try this:
var Comments = "Test Comments";
gr[comments].setJournalEntry(Comments);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 05:21 AM
GlideRecord on client scripts does not support all the methods available on the server. Are you able to refactor this to be part of a business rule or other server side code? If not, try using a GlideAjax call to pass the parameters to the server and create the record that way.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 06:03 AM
HI Chuck Tomasi,
Thanks for your reply.
I tried using the GlideAjax call inside the client script. Infact, the above script that i posted in my question, we are calling on OnSubmit of the catalog form. But, after refering to several post, i understood that we won't be able to use GlideAjax call on Onsubmit catalog client script. It seems like all the ways are closed for me to insert value to a Journal type field on Onsubmit client script.
Thanks,
Venu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2017 06:18 AM
What is the underlying requirement here? It feels like we are focused on a possible solution when we don't know what the problem actually is. If you're saving that information at submission type, why not use a before business rule and update the current record? One of the documented best practices is avoid using client scripts when a server script will work.
Reference:
ServiceNow Wiki: Technical Best Practices