ATF - Accessing reference variable sys_id in server side script

Archana Singh1
Tera Expert

Hi All,

Working on test case for creation of problem from incident. After submitting the incident form a problem record is created.

I want to access that record via the problem reference field from the incident. How to do that via server side script in atf?

Please let me know if we have any other alternative to achieve this as I need to open the problem record and then validate some field values.

Ps: Already tried via open problem record in the list view, but it doesn't seem to do anything after opening the list view.

 

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Archana,

Here is the approach I used to test the problem created from Incident.

I was able to open successfully the problem record which got created after clicking the UI Action "Create Problem"

Script Used in Run Server Side Script: I have given Step 3 sys_id since UI Action would be clicked from that incident

You give yours

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

	var incRec = new GlideRecord('incident');
	incRec.get(steps('21af3568db1d141059badd384b961901').record_id); // sys_id of step 3

	outputs.table = 'problem';
	outputs.record_id = incRec.problem_id;   
	stepResult.setOutputMessage("Successfully Found Problem record");
	return true;
	
})(outputs, steps, stepResult, assertEqual);

find_real_file.png

find_real_file.png

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

View solution in original post

15 REPLIES 15

Hi Archana,

please update it as below

ensure you use the record_id value while opening the problem in next step

Step 12 sys_id you need to use in query since that is the 3rd incident

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

var step12SysId = '';

var gr = new GlideRecord("problem");
gr.addQuery('first_reported_by_task, steps(step12SysId).record_id);  
gr.query();
if(gr.next()) {

outputs.table = 'problem';
outputs.record_id = gr.sys_id;
stepResult.setOutputMessage("This is the Problem sys_id: " + gr.sys_id);
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

Is this answered?

if my answer helped you, kindly mark it as Correct & 👍Helpful so that it does not appear in unanswered list & close the thread.

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Archana,

Here is the approach I used to test the problem created from Incident.

I was able to open successfully the problem record which got created after clicking the UI Action "Create Problem"

Script Used in Run Server Side Script: I have given Step 3 sys_id since UI Action would be clicked from that incident

You give yours

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

	var incRec = new GlideRecord('incident');
	incRec.get(steps('21af3568db1d141059badd384b961901').record_id); // sys_id of step 3

	outputs.table = 'problem';
	outputs.record_id = incRec.problem_id;   
	stepResult.setOutputMessage("Successfully Found Problem record");
	return true;
	
})(outputs, steps, stepResult, assertEqual);

find_real_file.png

find_real_file.png

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

Hi Ankur, 

This is working fine now.

Thanks for your help! 

 

Archana

 

 

Hi Ankur,

I am using the above server side script for one of my similar requirement. But getting error. Please find the screenshots below.

Please correct me if I m doing wrong.

find_real_file.png

find_real_file.png

Reference field on alert form

find_real_file.png

 

find_real_file.pngfind_real_file.png