Approval not geeting rejected

deepika46
Tera Contributor

Hello Experts,

 

In the sysapproval_approver table if we want to reject a request, first we have to add some comments and after that we can reject. Same thing i am doing via script and it is not Working. Can anyone tell me where i am doing wrong.

 

var app = new GlideRecord('sysapproval_approver');
app.addQuery('document_id', current.sys_id);//current is change requests sysid
app.addQuery('state', 'requested');//finding the record which are in requested state
app.query();
if(app.next())
{

gs.log("inside");//it is printinting
app.setValue('state', 'rejected');
app.setValue('comments', 'Rejected');

app.update();
}

 

The approval is not getting rejected.

 

deepika46_0-1700818863523.png

 

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Hi Deepika,

Can you replace 

app.addQuery('document_id', current.sys_id);//current is change requests sysid

with

app.addQuery('sysapproval', current.sys_id);//current is change requests sysid

 

Also, I assume you are using above script in BR and not scheduled job or Background script

yes @Jaspal Singh . i am using a BR. the query and all is going fine because it is going inside the if loop and printing the log statement.

Hi @deepika46 

Please use below:

var app = new GlideRecord('sysapproval_approver');
app.addQuery('document_id', current.sys_id);//current is change requests sysid
app.addQuery('state', 'requested');//finding the record which are in requested state
app.query();
if(app.next())
{
gs.log("inside");//it is printinting
app.setValue('state', 'rejected');
app.comments = 'Rejected';  // setValue will not set value of Journal field
app.update();
}

 

setValue() method is not supported for Journal Fields.

https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/field-administr...

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

i will update that addquery and try now