We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

approval.comment = 'place comments here'// if you place comments line in '' this also its not updated?


BALAJI40
Mega Sage

Hi Vaibhav,



try with this,


var approval = new GlideRecord('sysapproval_approver');


  approval.addQuery('sysapproval',number);


  approval.addQuery('approver',userID);


  approval.query();



  while(approval.next()){


  approval.comment = 'comments';   // give dots


  approval.state = 'rejected';


  approval.update(); // This one is enough, update reference will be used for reference fields


  }


Abhinay Erra
Giga Sage

Can you post the entire script?


vaibhavdesai
Kilo Expert

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.comment = comments;


  approval.state = 'rejected';


  approval.updateWithReferences();


  }


In log I am reeving all values. Not, Sure what is the issue. State is updated everytime. But, I guess because of journal field I am not able to write anything. As it is audited.