
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 06:54 PM
I am trying to copy Feature with all Stories, Tasks and Attachments from the Safe Application
I have a field on the Feature form called u_copy_storires with the UI Action conditoin of current.u_copy_stories!=""
I can get the Feature to copy over.
Stories will count how many are related to the feature, but copies the first one multiple time
For example - Feature has 5 Stories.
I can copy the Feature, the 5 unique new stories will be created, but only the first one is actually copied into the other 5.
I can not get tasks to populate at all and attachments are not coming over.
This is the UI Action that I have
Copy Feature and Stories
sn_safe_feature
Active
Show Insert
Show Update
Form Button
Condition: current.u_copy_stories!=""
//New Feature
var newFeature = new GlideRecord('sn_safe_feature');
newFeature.initialize();
newFeature.priority = current.priority;
newFeature.sn_safe_epic = current.sn_safe_epic;
newFeature.sn_safe_program = current.sn_safe_program;
newFeature.priority = current.priority;
newFeature.type = current.type;
newFeature.demand = current.demand;
newFeature.u_documentation_url = current.u_documentation_url;
newFeature.short_description = current.short_description;
newFeature.assignment_group = current.assignment_group;
newFeature.description = current.description;
var newFeatureID = newFeature.insert();
GlideSysAttachment.copy('sn_safe_feature', current.sys_id, 'sn_safe_story', newFeature.sys_id);
(current, previous);
//Retrieve Stories
var stories = new GlideRecord('sn_safe_story');
stories.addQuery('sn_safe_feature', current.getUniqueValue());
if (current.u_copy_stories=='Not Completed') {
stories.addQuery('state', '!=',3);
}
stories.query();
gs.info("STORIES RETURNED:{0}", stories.getRowCount());
while (stories.next()){
var newStory = new GlideRecord('sn_safe_story');
newStory.initialize();
newStory.sn_safe_feature = newFeatureID;
newStory.sn_safe_epic = current.sn_safe_epic;
newStory.sn_safe_program = current.sn_safe_program;
newStory.priority = current.priority;
newStory.type = current.type;
newStory.demand = current.demand;
newStory.u_documentation_url = current.u_documentation_url;
newStory.short_description = current.short_description;
newStory.assignment_group = current.assignment_group;
newStory.description = current.description;
var newStorySysID = newStory.insert();
GlideSysAttachment.copy('sn_safe_story', current.sys_id, 'sn_safe_story', newStory.sys_id);
(current, previous);
}
//Retrieve Tasks
var tasks = new GlideRecord('sn_safe_scrum_task');
stories.addQuery('sn_safe_story', current.getUniqueValue());
if (current.u_copy_stories=='Not Completed') {
stories.addQuery('state', '!=',3);
}
tasks.query();
gs.info("TASKS RETURNED:{0}", tasks.getRowCount());
while (stories.next()){
var newTask = new GlideRecord('sn_safe_scrum_task');
newTask.initialize();
newTask.sn_safe_story = newStorySysID;
newTask.priority = current.priority;
newTask.type = current.type;
newTask.assignment_group = current.assignment_group;
newTask.short_description = current.short_description;
newTask.description = current.description;
var newTaskSysID = newStory.insert();
GlideSysAttachment.copy('sn_safe_scrum_task', current.sys_id, 'sn_safe_scrum_task', newTask.sys_id);
(current, previous);
}
Can anyone point out where i am going wrong here?
Solved! Go to Solution.
- Labels:
-
Project Portfolio Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 08:40 AM
tasks.getValue('sys_id')
GlideSysAttachment.copy('sn_safe_scrum_task', tasks.getValue('sys_id'), 'sn_safe_scrum_task', newTaskSysID);
Also, for copying story attachments use below
GlideSysAttachment.copy('sn_safe_story', stories.getValue('sys_id'), 'sn_safe_story', newStorySysID);
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:52 PM
Hi
Few things to note here:
1. As you are copying from old feature to new then please substitute sn_safe_story
by sn_safe_feature
GlideSysAttachment.copy('sn_safe_feature', current.sys_id, 'sn_safe_story'
, newFeature.sys_id);
(current, previous);
2. Change newStory.sys_id
with newStorySysID
GlideSysAttachment.copy('sn_safe_story', current.sys_id, 'sn_safe_story', newStory.sys_id
);
(current, previous);
3. In the last GlideRecord on sn_safe_scrum_task
table. Please replace stories
with tasks
while (stories
.next()){
4. Also, in the second GlideRecord on sn_safe_story
table please replace current
with stories
.
var newStory = new GlideRecord('sn_safe_story');
newStory.initialize();
newStory.sn_safe_feature = newFeatureID;
newStory.sn_safe_epic = current
.sn_safe_epic;
newStory.sn_safe_program = current
.sn_safe_program;
newStory.priority = current
.priority;
newStory.type = current
.type;
newStory.demand = current
.demand;
newStory.u_documentation_url = current
.u_documentation_url;
newStory.short_description = current
.short_description;
newStory.assignment_group = current
.assignment_group;
newStory.description = current
.description;
5. if you want to copy over first story only to all the new ones then please replace while with if and inside if use a for loop and go over the total count returned by query.
Sample script:
var storiesCount = stories.getRowCount();
if(stories.next()) {
for(var i = 0; i < storiesCount.length ; i++) {
newStory.short_description = stories.getValue('short_description');
.
.
.
.
}
}
Please mark this helpful/correct, if applicable.
Regards,
Muhammad
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:31 PM
So these helped me somewhat
1. It took about 500 seconds to load
2. When it did load, it loaded the Feature with no problem. It only loaded the first story, then it copied over all of the tasks in the table, not just the ones that belong to the story.
Original
- Feature
- Story
- 1 Task
Copied Version
- Feature
- Story
- 300 Tasks in the table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:31 PM
//New Feature
var newFeature = new GlideRecord('sn_safe_feature');
newFeature.initialize();
newFeature.priority = current.priority;
newFeature.sn_safe_epic = current.sn_safe_epic;
newFeature.sn_safe_program = current.sn_safe_program;
newFeature.priority = current.priority;
newFeature.type = current.type;
newFeature.demand = current.demand;
newFeature.u_documentation_url = current.u_documentation_url;
newFeature.short_description = current.short_description;
newFeature.assignment_group = current.assignment_group;
newFeature.description = current.description;
var newFeatureID = newFeature.insert();
GlideSysAttachment.copy('sn_safe_feature', current.sys_id, 'sn_safe_feature', newFeature.sys_id);
(current, previous);
//Retrieve Stories
var stories = new GlideRecord('sn_safe_story');
stories.addQuery('sn_safe_feature', current.getUniqueValue());
if (current.u_copy_stories=='Not Completed') {
stories.addQuery('state', '!=',3);
}
stories.query();
gs.info("STORIES RETURNED:{0}", stories.getRowCount());
while (stories.next()){
var newStory = new GlideRecord('sn_safe_story');
newStory.initialize();
newStory.sn_safe_feature = newFeatureID;
newStory.sn_safe_epic = stories.sn_safe_epic;
newStory.sn_safe_program = stories.sn_safe_program;
newStory.priority = stories.priority;
newStory.type = stories.type;
newStory.demand = stories.demand;
newStory.u_documentation_url = stories.u_documentation_url;
newStory.short_description = stories.short_description;
newStory.assignment_group = stories.assignment_group;
newStory.description = stories.description;
var newStorySysID = newStory.insert();
GlideSysAttachment.copy('sn_safe_story', current.sys_id, 'sn_safe_story', newStorySysID);
(current, previous);
//Retrieve Tasks
var tasks = new GlideRecord('sn_safe_scrum_task');
stories.addQuery('sn_safe_story', current.getUniqueValue());
if (current.u_copy_stories=='Not Completed') {
stories.addQuery('state', '!=',3);
}
tasks.query();
gs.info("TASKS RETURNED:{0}", tasks.getRowCount());
while (tasks.next()){
var newTask = new GlideRecord('sn_safe_scrum_task');
newTask.initialize();
newTask.sn_safe_story = newStorySysID;
newTask.priority = tasks.priority;
newTask.type = tasks.type;
newTask.assignment_group = tasks.assignment_group;
newTask.short_description = tasks.short_description;
newTask.description = tasks.description;
var newTaskSysID = newTask.insert();
GlideSysAttachment.copy('sn_safe_scrum_task', current.sys_id, 'sn_safe_scrum_task', newTaskSysID);
(current, previous);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 08:35 PM
var tasks = new GlideRecord('sn_safe_scrum_task');
stories.addQuery('sn_safe_story', stories.getValue("sys_id")
);
Above will help you apply correct filter to get the tasks attached to the story.
Muhammad