UI Action/Business Rule to Auto Create a Story form a specific sc_task item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 02:17 PM
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);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 06:47 PM
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:
- 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:
Once done you will be able to see a Story Related List at the bottom of your catalog Task form as shown below:
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:
Replace "Test" mentioned in the filter conditions with your Text based on which you want to create a story
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 12:37 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2019 09:24 PM
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 05:41 PM
Hi,
If your query is resolved, kindly mark the answer as correct and close the thread.
Regards,
Shloke
Regards,
Shloke