Populating Additional Comments field with Record producer variable values

kushal2
Kilo Contributor

Hi Guys,

I am trying to set 'additional comments' journal field of change form with some answers given by end users for record producers. I can able to set same for existing record but when a new record is being created at the same time i want to set additional comments field. In my script I am getting current.sys_id as blank , so basically my question is how to return sys_id of newly created change request to record producer script?

Working code for existing record in record producer script

var gr1 = new GlideRecord('change_request');
gr1.addQuery('sys_id','adeec8501bc710109bda7596cc4bcbe8');
gr1.query();
if(gr1.next())
{
  gr1.comments.setJournalEntry('test');
  gr1.update();
}
 
Not Working code 
var gr1 = new GlideRecord('change_request');
gr1.addQuery('sys_id',current.sys_id);
gr1.query();
if(gr1.next())
{
  gr1.comments.setJournalEntry('test');
  gr1.update();
}
 
 

 

1 ACCEPTED SOLUTION

You do not need the current.update()

The assignment group is set? (so it gets to the part in the 'if (gr.assignment_group)')

Can you try removing current.update().

 

 

You are setting it in the 'Script', right?

find_real_file.png

View solution in original post

6 REPLIES 6

Willem
Giga Sage
Giga Sage

You do not have to query the record or update. Since it has to be created you can refer to current to set the values of the record that will be created, like this:

var gr1 = new GlideRecord('change_request');
gr1.addQuery('sys_id','adeec8501bc710109bda7596cc4bcbe8');
gr1.query();
if(gr1.next())
{
  gr1.comments.setJournalEntry('test');
  gr1.update();
}
 
current.comments = 'test';

 

For more info refer to:

https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...

kushal2
Kilo Contributor

current.comments = 'test'; is not working however I can set other values like short_description with the same syntax

current.short_description = "test";

 

I tried with current.comments.setJournalEntry('test') also but no luck. however when I am using setJournalEntry() with glideRecord its working.

In OOTB Record producers the "current.comments =" is used. So it should work.

Is the comments set somewhere else before?

You could try:

current.comments += 'test';

kushal2
Kilo Contributor

Still not working willem:(

 

var a = current.getValue('cmdb_ci');
    gs.addInfoMessage("Assignement group of CI=" + a);

  var gr = new GlideRecord('cmdb_ci');
    gr.addQuery('sys_id', a);
    gr.query();
    if (gr.next()) {
        gs.addInfoMessage("Support Group Found" + gr.assignment_group);
        if (gr.assignment_group) {
            current.assignment_group = gr.assignment_group;
   //gs.addInfoMessage("sys-id",current.sys_id);
   current.comments += 'test';
            current.work_notes += "Testing work notes";
   current.short_description = "Test Short Descrioption";
   current.update();
        } else {
            gs.addInfoMessage("CI not having group");
           current.setValue('assignment_group',id,name);
   
            current.update();
        }