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

Any speacial reason for using updateWithReferences instead of update?


-Anurag

Hi anurag,



No particular reason. even with update also it doesn't   work.


this is the second time this week someone said the same thing...for the same question = updateWithReferences




try to run this



var approval1 = new GlideRecord('sysapproval_approver');


  approval1.addQuery('sysapproval.sys_d',number);   //Make sure number is a sysid, else modify to sysapproval.number


  approval1.addQuery('approver',userID);   //also userId should be sys_id


  approval1.query();



  while(approval1.next()){


gs.log('haha');


  approval1.comment = comments;


  approval1.state = 'rejected';


  approval1.update();


  }


-Anurag

In your code, sysparm_number gets the sys_id right?


yes. Filters are working and i guess because of that only my state of approval is getting changed.