Automated Testing Framework (ATF) & Server Side Script

leochavez
Tera Guru

Within a ATF that I've created, I've managed to successfully extract the sysID of a record within the 'sys_user_grmember' table.  Test results show the following:

Step 8 (Record Query):
    Successfully found 2 sys_user_grmember records matching query:
    Group Group Name = Group A

Step 9 (Log):
    Group Member record sysID: 0cc18cacdb4fd340418f5840cf961905

Step 9 verifies that Step 8 is returning the sysID of the first queried record.  That said, I created a Step 10 and configured it to run the Server Side Script:

	var previousStepSysID = '707ffb41dbc3334058c12c8605961966';
	var grpMbrGR = new GlideRecord('sys_user_grmember');
	if (grpMbrGR.get(steps(previousStepSysID).record_id)) {
		outputs.table = 'sys_user_grmember';
		outputs.record_id = grpMbrGR.user.sys_id; // group member sysID
		gs.print("outputs: " + outputs.record_id);
		
		if (outputs.record_id) {
			stepResult.setOutputMessage("Group member found: " + grpMbrGR.user.name + "(" + grpMbrGR.user.sys_id + ")");
			return true;
		}
		
		stepResult.setOutputMessage("No group member record exists.  Verifiy sysID for previous step.");
		return false;
	}

The script above is my first attempt at using a Server Side Script and I'm sure I'm overlooking something, but the goal is to use sysID from Step 8, read the 'sys_user_grmember' and get the group member user sysID.  Test logs do not show any output for Step 10.

Is this the right approach?

- Leo

 

9 REPLIES 9

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi Leo

This is a bit strange. Are you writing those line of code under IIFE block default generated by Server Side Script? Can you please further try the following for debugging:

  1. Confirm if previousStepSysID is pointing to step #8. 
  2. Record ID in step #8 (i.e. 0cc18cacdb4fd340418f5840cf961905) is actually matching a record in sys_user_grmember i.e. <isntance>/sys_user_grmember.do?sys_id=0cc18cacdb4fd340418f5840cf961905 returns to a record and it has a user
  3. Just for a little more debugging in Step #10:
var previousStepSysID = '707ffb41dbc3334058c12c8605961966';
gs.info('confirming sysID ' + steps(previousStepSysID).record_id));
	var grpMbrGR = new GlideRecord('sys_user_grmember');
grpMbrGR.get(steps(previousStepSysID).record_id);
gs.info('is valid record ' + grpMbrGR.isValidRecord());
	if (grpMbrGR.isValidRecord()) {
		outputs.table = 'sys_user_grmember';
		outputs.record_id = grpMbrGR.user.sys_id; // group member sysID
		gs.print("outputs: " + outputs.record_id);
		
		if (outputs.record_id) {
			stepResult.setOutputMessage("Group member found: " + grpMbrGR.user.name + "(" + grpMbrGR.user.sys_id + ")");
			return true;
		}
		
		stepResult.setOutputMessage("No group member record exists.  Verifiy sysID for previous step.");
		return false;
	} else 
   gs.info('Could not find any group membeer record with sysID ' + steps(previousStepSysID).record_id);

 

 

--
Best Regards
Ankush

P.S. Please mark helpful/correct as appropriate to help the fellow community member in identifying the relevant answers.

leochavez
Tera Guru

Hi Ankush,

Thanks for replying.  Your assistance is appreciated.

I am running my code within an IIFE block default generated by Server Side Script.  Here is the full script:

(function(outputs, steps, stepResult, assertEqual) {
    var previousStepSysID = '707ffb41dbc3334058c12c8605961966';
    gs.info("confirming sysID '" + steps(previousStepSysID).record_id + "'");

    var grpMbrGR = new GlideRecord('sys_user_grmember');
    grpMbrGR.get(steps(previousStepSysID).record_id);
    gs.info("is valid record '" + grpMbrGR.isValidRecord() + "'");
    
	if (grpMbrGR.isValidRecord()) {
		outputs.table = 'sys_user_grmember';
		outputs.record_id = grpMbrGR.user.sys_id; // group member sysID
		gs.print("outputs: '" + outputs.record_id + "'");
		
		if (outputs.record_id) {
			stepResult.setOutputMessage("Group member found: " + grpMbrGR.user.name + "(" + grpMbrGR.user.sys_id + ")");
			return true;
		}
		
		stepResult.setOutputMessage("No group member record exists.  Verifiy sysID for previous step.");
		return false;
	} else {
        gs.info("Could not find any group member record with sysID '" + steps(previousStepSysID).record_id + "'");
        return false;
    }
    
    //return false;

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

After running the code above, I received the following output:

Step 8
    Record Query
    Success	Successfully found 2 sys_user_grmember records matching query:
    Group Group Name = Group A
		
Step 9
    Log
    Success	
    Group Member record sysID: 0cc18cacdb4fd340418f5840cf961905	9
		
Step 10
    Run Server Side Script
    Failure	
    Full logging from step execution:
    07:03:59 AM.646: Loading script: jasmine_lib/jasmine_custom.js
    07:03:59 AM.694: : confirming sysID 'undefined'
    07:03:59 AM.696: : is valid record 'false'
    07:03:59 AM.697: : Could not find any group member record with sysID 'undefined'

Odd that it's coming up 'undefined' when the ATF record record exists.  Could the API be at fault?

Both records (within their respective tables) exist:

  • Record Query (Step 8 sysID):
    • https://INSTANCE.service-now.com/sys_atf_step.do?sys_id=707ffb41dbc3334058c12c8605961966
  • User Group Member (Step 8 result):
    • https://INSTANCE.service-now.com/sys_user_grmember.do?sys_id=0cc18cacdb4fd340418f5840cf961905

Should I open a ticket with SNOW HI and have them look into it?

- Leo

leochavez
Tera Guru

Some progress....

The issue appears to reside in the retrieval of the group member sysID from Step 8, specifically with the 'steps' parameter.  That said, I hard coded the group member sysID (retrieved from Step 9) and Step 10 passed. 

OLD:

var grpMbrGR = new GlideRecord('sys_user_grmember');
grpMbrGR.get(steps(previousStepSysID).record_id); // get grp mbr rec sysID from Step 8

NEW:

var grpMbrGR = new GlideRecord('sys_user_grmember');
grpMbrGR.get('0cc18cacdb4fd340418f5840cf961905');  // hard coded grp mbr sysID

This is good in that I can move forward, but defeats the intent of the script in that I could have bypassed the script entirely and created a step with a hard coded value.

So either I've encountered a defect or am not invoking 'steps' parameter correctly.

- Leo

leochavez
Tera Guru

Update...

I've been going back and fourth with this and decided to open a ticket with SNOW HI.  I'll post results.

- Leo