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

Hey Kathy,

I'd likely refactor this, but in terms of your checklist requirement - you need to also copy the checklist items

 

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 existingCheckListID = checklistGR.getUniqueValue();
		//Copy checklist
        checklistGR.setValue('table' , story.getTableName());
		checklistGR.setValue('document' , story.getUniqueValue());
		var newCheckList = checklistGR.insert();
		
		if(!newCheckList){
			gs.error("Failed to copy checklist " + checklistGR.getLastErrorMessage());
			return;
		}

		//Copy checklist items
		var checkListItems = new GlideRecord('checklist_item');
		checkListItems.addQuery('checklist', existingCheckListID);
		checkListItems.query();
		while(checkListItems.next()){
			checkListItems.setValue('checklist' , newCheckList);
			checkListItems.insert();
		}
    }

this is getting me there, but not quite. It is pulling over checklist items that are not associated to enhancement record created story from.

this almost has me there, but it is pulling over checklist items that are not associated with the enhancement record I was on when initiated the create a story UI action

Check existingCheckListID has a valid value, otherwise when the following script attempts to run, it won't correctly filter the checklist item table

 

//Copy checklist items
		var checkListItems = new GlideRecord('checklist_item');
		checkListItems.addQuery('checklist', existingCheckListID);
		checkListItems.query();
		while(checkListItems.next()){
			checkListItems.setValue('checklist' , newCheckList);
			checkListItems.insert();
		}

Finally got story completed. For some reason, I could not get script provided to work (likely user error on my end) 🙂

 

I did find a BR script that copied checklist over from a demand to a project; made some modifications, and it worked.

 

Thanks so much for your assistance!