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

The SN Nerd
Giga Sage
Giga Sage

Create a server side UI Action called 'Submit Event'.

Might work well as a Related Link.

You code then becomes dead easy.

var msg = "Communication Channel:"+ " " + current.getValue("u_communication_channel").toString()
+ "\n"+
"Notification Sent To Vendor Representative?" + " " + current.getValue("u_send_vendor_update_on_current_event").toString()
+ "\n"
+"Content:" + " " +current.getValue("u_event_details");

current.u_activity_history.setJournalEntry(msg.toString());
current.setValue("u_event_details", "");
current.update();

if (current.getValue("u_send_vendor_update_on_current_event").toString() == "true") {
	gs.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 {
	gs.addInfoMessage("New event has been added to the activity. Watch all events in 'History' tab");
}

action.setRedirectURL(current);

 


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

The SN Nerd
Giga Sage
Giga Sage

Thinking about it more, it feel like you are using a string field like a journal field.

 

Why not then, create a new journal field for this?

Then, add it as a displayed field on the activity log.


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