Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

What info can you "push" within the Approval script answer.push

Markell
Tera Guru

More of a general question, but I was wondering what could be set with answer.push() in a Workflow approval script, beyond setting the approver.

 

For example if I wanted to push the approver and say comments or update the iteration field how would I go about that?

 

Example code below for reference:

 

answer =[];
var Approver = "";

var comments = "Hello World";

var grUser =new GlideRecord('sys_user');
grUser.addQuery('sys_id', '435453rr3454we544rrw'); //random text
grUser.addQuery('active',true);
grUser.query();
if(grUser.next()){

Approver = grUser.sys_id;
}

answer.push(Approver) 

 

----------------------------------------------

So the above would push/ set the user as an approver, but how would I push / set the comments as well on the created approval record?

I've tried A GlideAjax on the sysapproval_approver table afterwards, but I get the feeling this isn't possible in the same Approval activity as (I'm guessing) its (the approval request) not been created yet.

 

Thanks

 

1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage

Hi @Markell ,

 

In Approval activity of workflow, 'answer' is a variable defined out of the box. You can user this variable in below two ways :

 

1. You can use answer  as a string variable and populate it with comma separated user/group sys_id.

Example: answer = "8c2c91d7876a191052014087cebb35bc,0fe6bc82bf0221000ba9dc2ecf073987"  //Here answer will be treated as string

 

                                                                  OR

 

2. You can use answer  as an array, stroring user/group sys_ids. Below the example:

answer = []; //Here answer will be treated as an array

answer.push('sysID');

      .

      .

      .

answer.push('sysID');

 

So logically also it's not meaningful to store anything else.

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

View solution in original post

3 REPLIES 3

kamlesh kjmar
Mega Sage

Hi @Markell ,

 

In Approval activity of workflow, 'answer' is a variable defined out of the box. You can user this variable in below two ways :

 

1. You can use answer  as a string variable and populate it with comma separated user/group sys_id.

Example: answer = "8c2c91d7876a191052014087cebb35bc,0fe6bc82bf0221000ba9dc2ecf073987"  //Here answer will be treated as string

 

                                                                  OR

 

2. You can use answer  as an array, stroring user/group sys_ids. Below the example:

answer = []; //Here answer will be treated as an array

answer.push('sysID');

      .

      .

      .

answer.push('sysID');

 

So logically also it's not meaningful to store anything else.

 

I Hope this helps.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

Thanks Kamlesh

 

I will mark your response as accepted solution, but in your experience is there a way to set additional fields upon setting the new approval request? e.g updating the comments as mentioned?

Hi @Markell,

 

You can do such things using a BR on Approval table specifying proper condition like what will be source table and use Approving field to get relevant information from the related record, and set the additional fields:

 

kamleshkjmar_0-1666856163099.png

I Hope this helps.

 

Please mark this helpful if this helps

 

Regards,

Kamlesh