Create Story from using UI action

Swati251
Tera Contributor

Hello,

 

I have created an UI action to create a story from the enhancement. I have written a below code, but it is not working properly to create a story.

var story = new GlideRecord('rm_story');
story.state = '1'; //State - ready
story.short_description = current.short_description;
story.description = current.description;
story.assignment_group = current.assignment_group;
story.assigned_to = current.assigned_to;
story.enhancement = current.number;
story.opened_by = current.opened_by;
gs.info('New story is created ' + story.number');
gs.addInfoMessage('New story is created ' + story.number);

 

Thanks in advance!

 

4 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Swati251 

 

This is OOTB available

 

LearnNGrowAtul_0-1703852198280.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

Prathamesh G
Kilo Sage
Kilo Sage

Hello @Swati251,

 

You can correct your code with the below code:

 

var story = new GlideRecord('rm_story');
story.initialize();
story.state = '1'; //State - ready
story.short_description = current.short_description;
story.description = current.description;
story.assignment_group = current.assignment_group;
story.assigned_to = current.assigned_to;
story.enhancement = current.number;
story.opened_by = current.opened_by;
story.insert();
gs.addInfoMessage('New story is created ' + story.number);

 

If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

Thank You!

Prathamesh.

View solution in original post

Hello @Swati251 ,

 

It may your 'Enhancement' field will be reference field, so that's why that field is not being populated with the Enhancement number which is String. So please use the below code to to populate the Enhancement field on the story with the current number of the Enhancement. And to stay on your Enhancement record after clicking on the UI Action.

 

var story = new GlideRecord('rm_story');
story.initialize();
story.state = '1'; //State - ready
story.short_description = current.short_description;
story.description = current.description;
story.assignment_group = current.assignment_group;
story.assigned_to = current.assigned_to;
story.enhancement.setDisplayValue(current.number);
story.opened_by = current.opened_by;
story.insert();
//action.setRedirectURL(story); // Use to redirect to the created Story record
action.setRedirectURL(current); 
gs.addInfoMessage('New story is created ' + story.number);

 

If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

Thank You!

Prathamesh.

View solution in original post

Hello @Swati251 

 

It may your 'Enhancement' field will be reference field, so that's why that field is not being populated with the Enhancement number which is String. So please use the below code to to populate the Enhancement field on the story with the current number of the Enhancement. And to stay on your Enhancement record after clicking on the UI Action.

 

 

 

var story = new GlideRecord('rm_story');

story.initialize();

story.state = '1'; //State - ready

story.short_description = current.short_description;

story.description = current.description;

story.assignment_group = current.assignment_group;

story.assigned_to = current.assigned_to;

story.enhancement.setDisplayValue(current.number);

story.opened_by = current.opened_by;

story.insert();

//action.setRedirectURL(story); // Use to redirect to the created Story record

action.setRedirectURL(current); 

gs.addInfoMessage('New story is created ' + story.number);

 

 

If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

 

Thank You!

Prathamesh.

View solution in original post

9 REPLIES 9

Rene El Hamzh
Kilo Sage

Hi @Swati251

you need to add story.insert() to actually insert/create the record. 

 

Best regards,

Rene

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Swati251 

 

This is OOTB available

 

LearnNGrowAtul_0-1703852198280.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hello @Dr Atul G- LNG ,

 

Thank you for this. 

Prathamesh G
Kilo Sage
Kilo Sage

Hello @Swati251,

 

You can correct your code with the below code:

 

var story = new GlideRecord('rm_story');
story.initialize();
story.state = '1'; //State - ready
story.short_description = current.short_description;
story.description = current.description;
story.assignment_group = current.assignment_group;
story.assigned_to = current.assigned_to;
story.enhancement = current.number;
story.opened_by = current.opened_by;
story.insert();
gs.addInfoMessage('New story is created ' + story.number);

 

If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.

 

Thank You!

Prathamesh.