Tricky ATF Task: Get Related Field Value in Record Query

jmiskey
Kilo Sage

I have started pumping out some ATF testing, thanks in no small part to some of the help I have gotten from the Community here.  I am hoping that they can come through with another problem I have.

We have a Catalog Item where Manager's can set Delegates for their Employees on the Service Portal.  They go out to the Portal, bring up the Form, select their employee, fill out all the Delegation details, and click submit.  Once they submit, it creates a RITM and runs a Workflow that creates a delegation record in the sys_user_delegate table.

One thing that we did do was add a custom field tp the sys_user_delegate table named: u_ritm_number.  For delegate records that were created using this Form, it just captures the RITM number and stores it here, in string format.

So, I am trying to take advantage of this field in my ATF testing.  The first 7 steps of my testing are submitting a random request on the Service Portal.  Then, the 8th step is a Record Query step to confirm that the RITM record is created in the ServiceNow.  Steps 1-8 work flawlessly.

Now, I am trying step 9, which is to confirm that a record is added to the sys_user_delegate table.  What I am trying to do is to get the RITM number from the RITM that was created in the earlier steps, and query the sys_user_delegate table (on the u_ritm_number) field, and see if any records exist with that value.  The issue is, if I try to compare that field in the sys_user_delegate table, it is trying to compare it to the sys_id field from my earlier steps on the RITM.  I am not sure how to get the RITM Number field, and not the sys_id, to compare it to.

Here is what my ATF Steps look like:

find_real_file.png

find_real_file.png

 

And here is what the details on my last (failed) step look like:

find_real_file.png

It looks like it blanked out the value I tried to enter (because it was obviously wrong!).

Does anyone know how to accomplish what I am trying to do?

Thanks

1 ACCEPTED SOLUTION

OK I think I like Gerald's approach better.  It doesn't require a custom step (as he stated, it will not be reused).  If you add the "Run Server Side Validation Script", you should be able to paste the below modified script into the script box.

Find the step that queries the requested item table and returns the RITM sys_ID (I think it is 8 in your screen shot), right click on that step and choose copy sys_ID.  Paste that string in to replace "031b2ab52f7300106c32e83df699b6db" in my code.  That's how you get back to the result from that previous step.

 

(function(outputs, steps, stepResult, assertEqual) {
    var my_query_step_sys_id = "031b2ab52f7300106c32e83df699b6db"; //IMPORTANT: Replace this sting with the sys_id of the step earlier that does the query of the RITM

    var gr = new GlideRecord("sc_req_item");
    gr.get(steps(my_query_step_sys_id).first_record); // opens the "first record" returned by the previous query so we can use the number later

    var gr_d = new GlideRecord("sys_user_delegate"); //now searching the delegate table
    gr_d.addQuery("u_ritm", gr.getValue('number')); //where our string RITM number = the RITM.number
    gr_d.query();
    if (gr_d.next()) {
        //we have a result
        stepResult.setOutputMessage('Success!');
        stepResult.setSuccess();
        //you can set some more output vars here if you'd like or pass them in the success message above (e.g. who is the delegate)
        return true;

    } else {
        stepResult.setOutputMessage('Failure!');
        stepResult.setFailed();
        return false;
    }
})(outputs, steps, stepResult, assertEqual);

View solution in original post

10 REPLIES 10

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


It will be stored as document id and not as number. You will have to use Server Side script step and then store its output as number and use that to compare RITM Number field on delegate record.


Thanks,
Ashutosh

Thanks for the reply.  I have never used the Server Side Script action in ATF before.  How do I use it to get the Sys_ID of the previous step.  Do you have an example?

Thanks

Don Pfister
Kilo Guru

There may be other more elegant ways to do this, but one way would be with a custom test step config.

 

Create a new Test Step Config. 

 

Add an Input Variable like so:

find_real_file.png

This will capture the SYS_ID from the previous step.

In the step execution script add the following:

 

find_real_file.png

In the actual test, you add your new custom step and wire up the input variable to the previous step's output of the RITM SYS_ID

find_real_file.png

 

Hope this helps.

 

Don

 

 

You kind of lost me.  How do I "Create a new Test Step Config"?

That does not look like one of the Action options in ATF.