How to use G_Scratchpad to copy fields from Epic to Story?

Jessica Hall
Tera Expert

When I create a Story off an Epic, I want additional fields to copy to the Story. I know this happens with G_Scratchpad through a Business Rule and Client Script, but I'm new to both & hoping someone can help me with this! 

 

I believe the Business Rule used is "Update story created from epic" and the Client Script used is "Apply Information in scratchpad" on the Story table. Are these the correct two?

 

Also, how do I update the OOB scripting in the BR & CS to copy additional fields like Assignment Group and Assigned To? I've attached screenshots & copies of the scripting from both. 

 

Business Rule "Update story created from epic" 

g_scratchpad.scrum_pp_product = parent.product.sys_id;
g_scratchpad.scrum_pp_theme = parent.theme.sys_id;

 

Business Rule.png

 

Client Script "Apply Information in scratchpad" 

function onLoad() {

var storyHasProduct = g_form.getValue("product").length;
var product = g_scratchpad.scrum_pp_product;
if (!storyHasProduct && product)
g_form.setValue("product", product);

var storyHasTheme = g_form.getValue("theme").length;
var theme = g_scratchpad.scrum_pp_theme;
if (!storyHasTheme && theme)
g_form.setValue("theme", theme);

var storyHasRelease = g_form.getValue("release").length;
var release = g_scratchpad.scrum_pp_release;
if (!storyHasRelease && release)
g_form.setValue("release", release);

var storyHasSprint = g_form.getValue("sprint").length;
var sprint = g_scratchpad.scrum_pp_sprint;
if (!storyHasSprint && sprint)
g_form.setValue("sprint", sprint);

var storyHasEpic = g_form.getValue("epic").length;
var epic = g_scratchpad.scrum_pp_epic;
if (!storyHasEpic && epic)
g_form.setValue("epic", epic);

// Reset variables used in scratchpad so that they do not interfere with subsequent calls
g_scratchpad.scrum_pp_product = null;
g_scratchpad.scrum_pp_theme = null;
g_scratchpad.scrum_pp_release = null;
g_scratchpad.scrum_pp_sprint = null;
g_scratchpad.scrum_pp_epic = null;
}

 

Client Script.png

1 ACCEPTED SOLUTION

@Jessica Hall 

those were just placeholders for the fields.

You need to use the correct field name from the parent record in BR and correct field in g_form while setting it

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Jessica Hall 

are those OOB scripts?
you can enhance it further

something like this

BR

g_scratchpad.scrum_pp_product = parent.product.sys_id;
g_scratchpad.scrum_pp_theme = parent.theme.sys_id;

g_scratchpad.group = parent.<groupField>;

Client script

g_form.setValue('groupField',g_scratchpad.group);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

Thank you for your quick response! The BR & CS are both OOB. We have not altered them yet. Unfortunately, the Business Rule errored out with that new line. It allowed me to update if I removed the < > like this - 

 

g_scratchpad.group = parent.groupField;

 

However, adding that line to the BR & the new line to the CS did not copy the Assignment Group from the Epic to the Story. Any suggestions on how to update the scripting? Do I need the additional 3 script lines in with each new field? Example - 

 

var storyHasEpic = g_form.getValue("epic").length;
var epic = g_scratchpad.scrum_pp_epic;
if (!storyHasEpic && epic)

@Jessica Hall 

those were just placeholders for the fields.

You need to use the correct field name from the parent record in BR and correct field in g_form while setting it

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

Thank you! That worked to copy over the fields I needed.