UI Action Script to Populate Story with checklist items from Enhancement Record

Kathy D
Tera Contributor

I am tasked with creating or rather "updating" a current UI action.

 

It's for our "create a story" UI action from an enhancement record.

 

Our BAs will create a checklist on the enhancement record (it will not be a template and will be specific to each enhancement).

 

Upon the Create a Story UI action, I need the checklist item that were on the Enhancement record to populate to the Story checklist.

 

Any ideas now to achieve this?

 

Thanks in advance.

9 REPLIES 9

Kieran Anson
Kilo Patron

Hi, because a checklist can't exist until the record is saved, your business analyst would need to use the create story UI action and save the story before they could see the checklist. 

 

Would this limitation be suitable?

 

If so, you could modify the UI action to copy the checklist information across. However, would you want this behaviour whenever a story is created from an enhancement? Thinking long term, you could have a flow that auto-creates stories....would you want this checklist behaviour to work there? If so, an after business rule might be a better solution 

Hi Kieran,

 

I did modify the UI action script.

 

That's where my stuggle is as my scripting is still being developed:

 

Here is what I have so far that does not appear to be working.

 

Only showing what was added.

 

// (2) Copy checklist items from enhancement to story
    var checklistGR = new GlideRecord('checklist');
    checklistGR.addQuery('table_sys_id', current.sys_id); // Get checklist items for this enhancement
    checklistGR.query();

    while (checklistGR.next()) {
        var newChecklistItem = new GlideRecord('checklist');
        newChecklistItem.initialize();
        newChecklistItem.table_sys_id = story.sys_id; // Associate checklist with new story
        newChecklistItem = story.sys_id;
        newChecklistItem.name = checklistGR.name;
        newChecklistItem.order = checklistGR.order;
        newChecklistItem.insert();
    }
 
Any ideas regarding changes need to this script that I have on my UI action to create a story from the enhancement. I like the idea thinking long-term, but for now, we are looking for the checklist behavior to populate to the story after creation. I did save a story after creating it and checklist items did not carry over from the enhancement

 

 

Could you share the full UI action script? I'm not sure whether this is a fully custom UI action or something previously modified that you're also modifying.

 

Is the UI action set to "client" (is the box checked?)

Hello Kieran,

 

Client is "not" checked for the UI action.

 

I am modifying an existing UI action script, that was already rather lengthy.

 

Here is the entire script. I put in bold what I added.

 

createStory();

function createStory() {

    // (1) Copy defect fields into a new story
    var story = new GlideRecord("rm_story");
    story.priority = current.priority;
    story.short_description = current.short_description;
    //Modified for story STRY0100629
    if (current.u_enhancement_type == '2') {//u_enhancement_type=2  //state=-4
        story.assignment_group = '6f4dada8db826604f971f969af961959'; // sys_Id "ServiceNow Development= 6f4dada8db826604f971f969af961959"
    } else {
        story.assignment_group = current.assignment_group;
    }
    story.u_bus_analyst = current.assigned_to;
    story.u_stakeholders = current.u_requested_for + "," + current.watch_list;
    story.description = current.u_u || current.description; // Copy requirements notes if available;
    story.work_notes = current.work_notes;
    story.cmdb_ci = current.cmdb_ci;
    story.theme = current.theme;
    story.enhancement = current.sys_id;
    story.epic = current.u_parent_epic;
    //  story.parent = current.sys_id;
    story.type = "Development";
    story.opened = current.opened;
    story.opened_by = gs.getUserID();
   
    //Modified for story STRY0100629
    story.state = -6; // draft    // story.state = 12; // idea
    story.insert();
    GlideSysAttachment.copy('rm_enhancement', current.sys_id, 'rm_story', story.sys_id);

 // (2) Copy checklist items from enhancement to story
    var checklistGR = new GlideRecord('checklist'); // Assuming the checklist table is 'checklist'
    checklistGR.addQuery('table_sys_id', current.sys_id); // Get checklist items for this enhancement
    checklistGR.query();

    while (checklistGR.next()) {
        var newChecklistItem = new GlideRecord('checklist');
        newChecklistItem.initialize();
        newChecklistItem.table_sys_id = story.sys_id; // Associate checklist with new story
        newChecklistItem = story.sys_id;
        newChecklistItem.name = checklistGR.name;
        newChecklistItem.order = checklistGR.order;
        newChecklistItem.insert();
    }

    story.product = current.product; //the product has to occur after the insert as it will conflict with the story's epic in some situations
    story.update();


    // (3) Redirect webpage to the new story (Ensure story displayed in scrum view)
    gs.addInfoMessage(gs.getMessage("Story {0} created", story.number));
    action.setRedirectURL(story);
    var redirectURL = action.getRedirectURL();
    redirectURL = redirectURL.replace("sysparm_view=", "sysparm_view=scrum");
    action.setRedirectURL(redirectURL);
    action.setReturnURL(current);
}

function getNewState(current) {
    if (current.state == -5) return -6; // draft -> draft
    if (current.state == 2) return 2; // work in progress -> work in progress
    if (current.state == 4) return -8; // testing/qa -> testing
    if (current.state == 11) return -5; // on hold -> blocked
    if (current.state == 3) return 3; // closed complete -> complete
    if (current.state == 7) return 4; // cancelled -> cancelled
    if (current.state == -4) return -6; // scoping -> draft
    if (current.state == -3) return 1; // awaiting approval -> ready
    if (current.state == 10) return 3; // deploy/launch -> complete
    return current.state;
}

if(current.state == '-4'){//stateIN-15{
    current.state ='-15';
    current.update();
   
}