How to set a new journal entry in client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2018 09:24 AM
Hi all,
I am using a client script to add a button next to one of the fields in a form I created and on click on the button, I would like to add a new entry to a journal field for the table behind the form (name "u_activity_history").
The button is added successfully, but a new entry is not added to the journal.
What am doing wrong?
The script I am using is below (The entry to the journal is in "submitEvent" function)
Please Advise.
Thanks!
function onLoad() { var field = 'u_send_vendor_update_on_current_event'; field = g_form.tableName + '.' + field; try{ $(field).insert({ after:'<button id="submit_new_event" name="submit_new_event" onclick="submitEvent()" type="button">Submit Event</button>' }); } catch(e){ } } function submitEvent() { var msg = "Communication Channel:"+ " " + g_form.getValue("u_communication_channel").toString() + "\n"+ "Notification Sent To Vendor Representative?" + " " + g_form.getValue("u_send_vendor_update_on_current_event").toString() + "\n" +"Content:" + " " +g_form.getValue("u_event_details"); var incRec = new GlideRecord("u_lp_vendor_activity"); incRec.addQuery("sys_id", g_form.getUniqueValue()); incRec.query(); if(incRec.next()){ incRec["u_activity_history"].setJournalEntry(msg.toString()); incRec.update(); g_form.setValue("u_event_details", ""); } if (g_form.getValue("u_send_vendor_update_on_current_event").toString() == "true") { g_form.addInfoMessage("New event has been added to the activity and Email will be sent to the Vendor's representative shortly. Watch all events in 'History' tab"); } else{ g_form.addInfoMessage("New event has been added to the activity. Watch all events in 'History' tab"); } try{ action.setRedirectURL(current); } catch(err) { // do nothing } }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 12:43 AM
That is because you are writing client script using server side API.
If you are not submitting the record, then why is there a redirect call?
action.setRedirectURL(current);
You really should be using GlideAjax for this too.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 02:38 AM
I used the
action.setRedirectURL(current);
to load the page again, in order for the record to refresh and show the new journal entry. Is there a better way to do this?
As for the GlideAjax: I can't find any documentation on how to set an "HTTP put" request, all documentation is about the "HTTP get". Can you please add a reference for this?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2018 05:34 PM
If you are refreshing the page, you may as well just use a server side UI Action for you code.
I don't think you can really achieve what you want client side, without breaking many best practices and increasing code complexity.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2018 05:49 PM
Hi TD,
I'm not sure using a client script in this way is advisable. I'd probably consider using a UI Action for adding a button if you want it done client-side or a business rule to do it server-side (I would likely use async update so that it's not blocking).
Anyway, as to the GlideAjax question, if you make a Script Include that is client callable, you will be able to use GlideAjax as such:
var request = new GlideAjax(<class name>);
request.addParameter("sysparm_name", <method name>);
request.addParameter("sysparm_msg", <msg text>);
request.getXMLAnswer(function (response) {
// check to see if it was successful here.
});
Your Script Include could use this.getParameter("sysparm_msg") to get the parameter.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2018 05:53 PM
I agree with Matt.
I'd strongly suggest that you get this working purely server side first, especially if you are new to ServiceNow.
Once you have that working, you could consider abstracting into a Script Include, then use Glide Ajax to call that logic.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022