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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Archana,

Can you share the test steps you did till now?

How the problem is created? Is it via UI Action?

Regards
Ankur

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

Archana Singh1
Tera Expert

Hi Ankur,

Here we are creating 3 incident records, after the last incident is submitted a problem record is generated.

I wish to access that record.

Hi Archana,

I could see you are creating 3 incidents; but where is the step to create problem

Can you try to add step for click UI Action Create Problem; after this you can try for Run Server Side Script step

Regards
Ankur

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

Hi Ankur,

We are using Business Rule for problem record creation instead of UI Action.

When we are submitting 3 incident record, then after the submission of third incident form a problem record gets created.

As mentioned in step 14 of my test case, there am trying to validate that the problem field under Related Record tab on the incident form is not empty.

Test case is running successfully till this step.

Further, I want to open that problem record now for validating some field values.

I am trying to use server side script for achieving this.

Please note, there is a field on the problem form, First reported by (first_reported_by_task) which contains the value of 3rd incident number.

Please check:

(function(outputs, steps, stepResult, assertEqual) {
    // add test script here
	
    var gr = new GlideRecord("incident");
    prb = current.problem_id;
    gr.addQuery(prb, 'sys_id');
	gr.addQuery(prb.first_reported_by_task,'steps(1c505c80db115450c3ab0661f3961990)');  
	gr.query();
    while (gr.next()) {
    stepResult.setOutputMessage("This is the Problem sys_id: " + prb);
 }
    outputs.table = 'problem';
    outputs.record_id = prb;
	
})(outputs, steps, stepResult, assertEqual);

Here sys_id I am using from step 13.

Hope this clears the scenario!

 

Thanks