Add text to a Journal field using a UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 07:50 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 07:54 AM
I wonder if part of the issue is that the comment field is on the task table and the form is the sc_task form. So, I need to somehow tell it to write to the comments field that is on the task table but referenced on the sc_task form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 07:55 AM
Hi,
please try using setJournalEntry() Function. It would be like:
current.comments.setJournalEntry("The String you want to be added to Comments"); - This case when we are setting to the same table. If different table you got to make changes. But for setting Journal field you can use this option.
Thanks and Regards,
Saran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 08:03 AM
I tried what you suggested, but alas, it did not work.
I did read in the wiki article that journal fields don't work with setValue. I tried something similar to what they have listed in the wiki article, but wasn't successful.
6.1 setValue()
The setValue() method is not supported for Journal fields. Instead, assign values in script as in the following example.
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."; gr.update(); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2015 10:02 AM
Simply this should work.
current.comments="this is a new comment";
current.update();