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.

Update multiple records for testing cases in ATF

misprak
Tera Contributor

We have a custom table(xyz) in which records are inserted based on some condition on incident table. The number of records inserted is dynamic based on certain policies.
Now, I can move the incident to resolved state only if the assigned to person marks these related records as Completed.
How can we achieve the step of -"assigned to person completing the related records" in ATF?

8 REPLIES 8

Hi @Dr Atul G- LNG 

Also, not by using 'run server side script' test step?

Regards
Prakhar

Hi @misprak 

 

Can be a option, I am not coder, so tough to say it will be done, but give a try and share feedback.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @misprak,

Give a try with run server side script. (Example: I have tried on Problem record with n number of tasks with below code and it works).

Sample Code: Change the table names as per your requirement (Note: Set the mandatory fields on task in script which might block submission). Attached the sample code at attachment for your reference.

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

(function(outputs, steps, params, stepResult, assertEqual) {
    var gr = new GlideRecord('problem_task'); //(This should be child task table)
    gr.addQuery('problem=' + steps('6ea06f0d93410610db7af6027cba100c').record_id); //(Problem should be replaced with your scenario parent table)
    gr.query();
    while (gr.next()) {
        gr.state = '157'; (Replace with task table state backend value)
        gr.setWorkflow(false);
        gr.update();
    }
    var grCount = new GlideRecord('problem_task'); //(This should be child task table)
    grCount.addQuery('problem=' + steps('6ea06f0d93410610db7af6027cba100c').record_id + '^state!=157'); //(Problem should be replaced with your scenario parent table)
    grCount.query();

    if (grCount.getRowCount() >= 1) {
        stepResult.setOutputMessage("Failed to delete task record");
        return false// pass the step
    } else {
        stepResult.setOutputMessage("Successfully Set task record to closure state");
        return true// fail the step
    }

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

sushmapinapati
Tera Contributor

Hi @misprak,

Give a try with run server side script. (Example: I have tried on Problem record with n number of tasks with below code and it works).

Sample Code: Change the table names as per your requirement (Note: Set the mandatory fields on task in script which might block submission). Attached the sample code at attachment for your reference.

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

(function(outputs, steps, params, stepResult, assertEqual) {
    var gr = new GlideRecord('problem_task'); //(This should be child task table)
    gr.addQuery('problem=' + steps('6ea06f0d93410610db7af6027cba100c').record_id); //(Problem should be replaced with your scenario parent table)
    gr.query();
    while (gr.next()) {
        gr.state = '157'; (Replace with task table state backend value)
        gr.setWorkflow(false);
        gr.update();
    }
    var grCount = new GlideRecord('problem_task'); //(This should be child task table)
    grCount.addQuery('problem=' + steps('6ea06f0d93410610db7af6027cba100c').record_id + '^state!=157'); //(Problem should be replaced with your scenario parent table)
    grCount.query();

    if (grCount.getRowCount() >= 1) {
        stepResult.setOutputMessage("Failed to delete task record");
        return false; // fail the step
    } else {
        stepResult.setOutputMessage("Successfully Set task record to closure state");
        return true; // pass the step
    }

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