Accessing multiple catalog task in ATF

Supritha3
Tera Contributor

Hi,

In a catalog item that i am testing in ATF the workflow is as such, that it generates multiple catalog tasks(around 15) for a single RITM, i am able to query the sc_task table for all these records, but now i need to access each record and close task for each of them. I tried using the "run server side script",

var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('request_item=grTask.number^state=Open');
grTask.query();
while (grTask.next()) {
gs.log('CATNum:'+grTask.number);
grTask.state="Closed Complete";
}

but i do not see the state to be "Closed Complete" for all records. Please help me get a solution.

Regards,

Supritha 

15 REPLIES 15

Hi Supritha,

try what Ashutosh has mentioned; use previous step sys_id

Can you share what is the step prior to this; this would help to know output of the previous step

Also close complete is having value as 3

Also open state is having value as 1

updated script below

(function(outputs, steps, stepResult, assertEqual) {
    // add test script here

var requestId = steps('01839145db30ab808812644a4b9619cc').record_id;

var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('state=1^request_item=' + requestId);
grTask.query();
while (grTask.next()) {
gs.info('CATNum:'+grTask.number);
grTask.state = 3;
grTask.update();
}

stepResult.setOutputMessage("Successfully Closed SC Tasks");
	stepResult.setSuccess();
	return true;
	
})(outputs, steps, stepResult, assertEqual);

Mark āœ… Correct if this solves your issue and also mark šŸ‘ Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

Supritha3
Tera Contributor

Hi Ankur,

I have followed the below steps after "order catalog item":

find_real_file.pngFor the sys_id i have used the id from step 9 if it is right.The server side script is running successfully but the catalog tasks are still not getting closed as you can see below.

find_real_file.png

 

Regards,

Supritha

Hi Supritha,

Ideally the records which are created during ATF Test running are roll-backed after test successfully completes;

i.e. ideally you should not be able to locate the RITM, Catalog Tasks etc in the instance as they were created as part of testing and should get deleted automatically

There is no need to store these records ideally as they were just used for testing purpose

https://docs.servicenow.com/bundle/orlando-application-development/page/administer/auto-test-framewo...

https://hi.service-now.com/kb_view.do?sysparm_article=KB0714767

check whether RITM and Catalog Task tables are configured to exclude

If you want to check whether "Exclude from Rollback" is set to "true"/"false" on RITM. Navigate to list of view RITM, SC TASK

1)Select Configure Dictionary from List Context Menu options

2)Select the row which has no column name which is empty

3) Choose Advanced View -> In the attributes check if 'excludeFromRollback=true' is added

Mark āœ… Correct if this solves your issue and also mark šŸ‘ Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

@Supritha 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

 

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

Supritha3
Tera Contributor

Hi Ankur,

Well both the images i have attached are from the test results. The Records were being rolled back as expected but my doubt is that the server side script is not helping to set the state values of the catalog task to "close complete" while the test was still running.I could see the record in the client test runner itself and it was there were i noticed that the state is not getting changed.

Regards,

Supritha