UI Action/Business Rule to Auto Create a Story form a specific sc_task item

ijaggers
Tera Contributor

I am trying to build a UI action/Business rule to Create an Agile Story when a Catalog request is submitted for a ServiceNow Enhancement. I wanted to copy the OOTB Create Problem UI action /Business rule. Coding isn't something I do so i'm having a hard time finding the right codes to replace Incident and problem in the OOTB script. I would aslo like them to create a parent child relationship and added to related lists for both sc_task and story.

I created a catalog item with a custom workflow that creates a sc_task and assigns it to the group that would work the ticket.

 

Based on the SC Task Short description it should auto create story based on parameters from that sc_task. Below are the scripts i've been working with.

 

- UI Action Script -

Condition:

current.task_state != TaskState.CLOSED && current.Story_id.nil()

Script:

var story = new TaskUtils().getStoryFromTask(current);

if(story != undefined) {
    current.story_id = story.insert();
    var mySysID = current.update();
    gs.addInfoMessage(gs.getMessage("Story {0} created", story.number));
    action.setRedirectURL(story);
    action.setReturnURL(current);
} else {
    action.setRedirectURL(current);
}

 

- Business Rule Script -

** I know this is wrong as it should dot walk to current variables and then the name since all the data on the sc_task item is on the variables.

(function executeRule(current, previous /*null when async*/) {

var story = new GlideRecord("Catalog Task");
story.short_description = current.short_description;
story.description = current.description;
story.product = current.product;
story.theme = current.theme;    
story.priority = current.priority;
story.company = current.company;
story.sys_domain = current.sys_domain;
var sysID = story.insert();

current.story_id = sysID;
var mySysID = current.update();

gs.addInfoMessage("Story " + story.number + " created for SNOW Enhancement task");
action.setRedirectURL(current);


})(current, previous);

6 REPLIES 6

shloke04
Kilo Patron

Hi,

 

In order to achieve your solution, please follow the below steps:

 

  • Navigate to your Catalog Task Form and then click on the Form Header and select Configure--> Related List as shown below:

find_real_file.png

 

 

  • Then search for this Related List as shsown below and add it to your form which will show your relationship between Story and Catalog Task Table:

 

find_real_file.png

 

Once done you will be able to see a Story Related List at the bottom of your catalog Task form as shown below:

 

find_real_file.png

 

 

 

Now Finally Write a After Insert Business Rule(You can keep it as After insert or Update Business rule based on your requirement) on the Catalog Task Table with conditions as "short Description Contains "Your Text" with the script mentioned below:

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var stry = new GlideRecord('rm_story');
	stry.initialize();
	stry.short_description = current.short_description; //Replace with any field Name you want to copy from
	stry.parent = current.sys_id;
	stry.insert();

})(current, previous);

 

Please refer the screenshots below for more details:

 

find_real_file.png

 

Replace "Test" mentioned in the filter conditions with your Text based on which you want to create a story

 

find_real_file.png 

 

Similarly along with Short Description, you can populate other field values as well:)

 

Hope this help. Please mark the answer as helpful/correct based on impact.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

This is working to create that parent/child relationship but it isn't transferring the data on to the story. I want to match variables on the task form.

Here is what I'm using but I'm not sure why it isn't passing the variables:

 

(function executeRule(current, previous /*null when async*/) {

        // Add your code here
    var stry = new GlideRecord('rm_story');
    
    stry.initialize();
    stry.short_description = current.variables.short_description;
    stry.description = current.variables.description;
    stry.product = current.variables.product;
    stry.theme = current.variables.theme;
    stry.priority = current.variables.priority;
    stry.parent = current.sys_id;
    stry.insert();

})(current, previous);

Chaithanya10
Tera Contributor

Hello,

 

You have to use story.initialize(); method after the below line.

var story = new GlideRecord("Catalog Task");

or elase you can use directly related list "Story-->parent".

shloke04
Kilo Patron

Hi,

 

If your query is resolved, kindly mark the answer as correct and close the thread.

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke