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.

Create Test UI button for stories

Scotty88
Tera Contributor

I would like to create a 'Create Test' UI button on the story form in the agile module so that you can easily create a testing task (sn_test_management_test) form the form, is this something that anyone has done? Have not had much experience with doing this

8 REPLIES 8

Mark Manders
Mega Patron
var testTask = new GlideRecord('sn_test_management_test')'
testTask.initialize();
testTask.fieldA = current.storyFieldA;
testTask.fieldB = current.storyFieldB;
testTask.fieldC = 'abc';
testTask.story = current.getUniqueValue();
testTask.insert();

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Scotty88
Tera Contributor

Thanks however this just creates a blank test record not asscoiated with anything? I want to be able to click the UI button (Create Test) from the story form and then it takes me to the create test form where I can create and test and then when I save it, it is associated with the story (as per screen shots)

Scotty88_0-1723785877813.png

 

Scotty88_1-1723785952432.png

 

Scotty88_2-1723786254848.png

 

 

Hi @Scotty88 ,
On clicking the UI action, if you want to open a new tab, then add the below line to the code of the @Mark Manders .

action.setRedirectURL(action);

So, the final code would be: 

 

var storyTest = new GlideRecord('sn_test_management_test');
storyTest.initialize();

storyTest.parent = current.getUniqueValue(); // Set the testStory Parent field to the current stroy, so that it would be associated to the story and shown in the parent list.

storyTest.short_description = current.short_description; // if you want to copy the short description of the story and push it into the test created.

storyTest.insert();

action.setRedirectURL(storyTest);  // on clicking the UI action, it redirects to the new record.

 

 

If this information helps you, kindly mark it as helpful!

Regards,
Najmuddin.

So I actually need it to open on this part (see below) with the option to populate a predfined short descripion and test steps and then when I save or submit it saves the test to the parent story. I tried just updating the table name on the above script however that is not working?

 

Scotty88_0-1724109880833.png