How to set a new journal entry in client script?

TD14
Kilo Contributor

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
}
}

 

11 REPLIES 11

Allen Andreas
Administrator
Administrator

What about?

incRec["u_activity_history"].comments=msg;

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

TD14
Kilo Contributor

Thanks, Allen. Unfortunately, it's not adding a new entry to the Journal. Any other suggestions? 

The SN Nerd
Giga Sage
Giga Sage

If you are immediately submitting after the journal entry is added, why not do it Server Side?


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

TD14
Kilo Contributor

Hi Paul, 

Thanks for the response.

I wanted to submit the update, but don't exit the form.

I added try and catch for 

incRec["u_activity_history"].setJournalEntry(msg.toString());

The error is: incRec.u_activity_history.setJournalEntry is not a function

 

When I run Allen's suggestion: 

incRec["u_activity_history"].comments=msg;

It's not throwing an exception, but the journal is not updated.