How to enter value in "Journal Input" type field using server side script?

vaibhavdesai
Kilo Expert

Hello,

I have written below code to update my approval status and rejection comments on approval table. My state is updated but I am facing issue in updating value in comment field. It is Journal input field.

var approval = new GlideRecord('sysapproval_approver');

  approval.addQuery('sysapproval',number);

  approval.addQuery('approver',userID);

  approval.query();

  while(approval.next()){

  approval.comment = comments;

  approval.state = 'rejected';

  approval.updateWithReferences();

  }

Thanks you in advance. Help is really appreciated.

Regards,

Vaibhav Desai

1 ACCEPTED SOLUTION

You know what, your field name is incorrect here. It should be comments and also use update here. You do not need updateWithReferences()



var comments = this.getParameter('sysparm_comments');


  var number = this.getParameter('sysparm_number');


  var userID = this.getParameter('sysparm_userID');


  gs.log(">>>>>>>>>>>>COMMENTS   "+comments+" NUMBER "+number+" USER ID "+userID);



  var approval = new GlideRecord('sysapproval_approver');


  approval.addQuery('sysapproval',number);


  approval.addQuery('approver',userID);


  approval.query();



  while(approval.next()){


  approval.comments = comments;


  approval.state = 'rejected';


  approval.update();


  }




View solution in original post

17 REPLIES 17

Anurag Tripathi
Mega Patron
Mega Patron

Journal field is set like any other field   no difference



eg:


current.comments = 'this is an example comment';


current.update();


-Anurag

Hello Anurag,



I found this, Delete or Update Activity log and Journal Field Entries - ServiceNow Guru



Not sure how to use it in my script include.


Make sure you have not used setWorkflow(false) , otherwise it will not work. comments wont get updated.


-Anurag

Hello anurag,



Yes i confirm I haven't used setWorkflow(false).