How to approve a catalog task in an ATF

mkader
Kilo Guru

Hello,

I have an ATF that I created. It involves ordering an item from the Service Portal. When I get to the approval process and marking tickets as Closed Complete, I jump to the server section and use the Replay Request Item. This allows me to grab the ticket number.

find_real_file.png

Where my test is failing:

It fails at Step 15. I am trying to do a Record Query to get back the sc_task and close the task, but the error I keep getting is "No records matching query" as shown below:

find_real_file.png

This is what my query step looks like:

find_real_file.png

Once this step is figured out, I want to add a Record Update to close the sc_task.

**Note**

When an item is ordered on our portal, closing the task does not close the RITM and closing the RITM does not close the REQ. This is a manual process. The RITM and SCTASK display as a related list under the REQ at same time and I think that is whats making this so difficult.

 

Thanks!

1 ACCEPTED SOLUTION

Okay thanks for your reply 🙂

I would suggest below steps:

1)- Record Query : sysapproval_approver [Step 13 already in place]

- Approval For: Pass the request item

- Retrieved atleast one record

2) Open an existing record (pass the id return in above step)

3) click a ui action (here please select ui action:approve)

[Note: Please don't use record update to change it to approved] instead use step 2 & 3

If you have some queries please feel to ask:)

 

View solution in original post

16 REPLIES 16

Deepen Shah
Kilo Guru

Hi

Please make sure entry is created in 'sc_task' with same request and in Open state, which you are checking at step15?

Regards
Deepen shah
aavenir.com

I am currently doing that in step 15. I am unable to get the request approved. If the request is not approved, then the SCTASK does not get created.

 

I have a server script that I just wrote, but have no idea how to execute it on the approval. Which step am I taking the Sys_ID from. 

 

(function(outputs, steps, stepResult, assertEqual) {
    var chg = steps('a4b4a2e5db969010ff43692b13961942');
	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('document_id.sys_id', '=', chg);
	gr.addQuery('state', '!=', 'approved');
	gr.query();
	
	while(gr.next()) {
		gr.state = 'approved';
		gr.update();
	}

})(outputs, steps, stepResult, assertEqual);

@mkader 

you should use the step which gives you the RITM sys_id i.e. step number 8 "Record Query"

please update as this so that the RITM is approved

Use this updated script

(function(outputs, steps, stepResult, assertEqual) {
var chg = steps('SYS ID STEP 8').first_record; // give sys_id of step number 8
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', chg);
gr.addQuery('state', '!=', 'approved');
gr.query();

while(gr.next()) {
gr.state = 'approved';
gr.update();
}

// these lines are required to know the outcome

stepResult.setOutputMessage("Successfully Approved RITMs");
return true;

})(outputs, steps, stepResult, assertEqual);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you for your response. I just tested what you provided me and took the sys_id from step 8. It says it passed, but when I had the request opened the state did not change. I was also able to verify it did not work because an sctask was not created. When the Request is approved an SCTASK gets created

On sysapproval_approver table, the state field is disabled. Could this be throwing the error? Also, there is a UI Action "Approve". How can I trigger the UI Action? maybe that can be another workaround