Add text to a Journal field using a UI Action

richelle_pivec
Mega Guru

I have a UI Action called "Create Request" which is button on my Task form. I'd like to have some text that writes to "comments" journal field. I've tried the same format below with "current.", but that doesn't seem to work for journal fields.

Here is what I'd like to add to that comments field: This request has been closed and an IT catalog request has been opened in your name. You will receive an email when it is completed.

Here is the script I am using (built from help here on the community):

//Update saves task before going to the catalog homepage

current.u_related_request_below = true;

current.state = 3;

current.closed_at = gs.nowDateTime();

current.assigned_to = gs.getUserID();

current.update();

gs.addInfoMessage(' ' + current.number + ' has been closed to make this request');

var shopCart = new GlideRecord('sc_cart');

shopCart.addQuery('user',gs.getUserID());

shopCart.query();

while (shopCart.next()){

    shopCart.deleteRecord();

}

var newCart = new GlideRecord('sc_cart');

newCart.user = gs.getUserID();

newCart.requested_for = current.caller_id.sys_id;

newCart.special_instructions = "Request for " + current.number;

newCart.insert();

var url = "catalog_home.do?sysparm_view=catalog_default&sysparm_processing_hint=setfield:request.parent=";

url += current.sys_id;

action.setRedirectURL(url);

thanks,

Richelle

6 REPLIES 6

Alas, that does not seem to work for journal fields. I tried it for both the journal field that is on a different table and referenced here (comments on the task table being referenced on sc_task table) and the u_work_notes journal field I have on the sc_task table and on this form. The non-journal-ed fields all work just fine using "current." but the journal fields need something else.


Thanks for the advice though...



Richelle


journal fields also work in this way only, here is an eg from WIKI




var gr = new GlideRecord('incident');



//query priority 1 incidents in the state of either 'new' or 'active'.


gr.addQuery('priority', 1);


var gc = gr.addQuery('state', 1);


gc.addOrCondition('state', 2);


gr.query();



while(gr.next())


{



//print a list of the incident numbers updated


gs.print(gr.number);



//add an entry to the 'work notes' journal field for each incident


gr.work_notes = "This is a high-priority incident. Please prioritize.";       //this is the journal field getting the value


gr.update();


}


-Anurag