Clone Visual Task Board

corbinhicks
Kilo Contributor

how can i clone my task board? for example, i have a task board of change requests for Applications team and I'd like to be able to clone that list for the Infrastructure team

5 REPLIES 5

Aditya Telideva
ServiceNow Employee
ServiceNow Employee

ISorry but there is no way within a Visual Task Board itself to clone it,   But, you can do this on the form itself (the vtb_board table) by creating a UI Action to do the clone, including the respective lanes (vtb_lane). I quickly hacked together a sample   Script Include as a proof of concept which I have attached.



You can then create the UI Action and call the utility with a script like:




  1. // Clone the board  
  2. var originalBoard = current.name;  
  3. var clonedBoard = (new VTBCloneUtil()).cloneBoard(current);  
  4.  
  5.  
  6. // Redirect to the new board  
  7. action.setRedirectURL(clonedBoard);  
  8. gs.addInfoMessage(gs.getMessage("Cloned from {0} board", originalBoard));  


I hope this helps you achieve your requirements



Regards, Aditya Telidevara


Did this also clone the members within that board or just the board/lanes itself?

Heather White
Mega Guru

I tried this in my instance and was not able to make it work properly-can you walk me through the set up?

 

Thanks!

 

Heather

benn23
ServiceNow Employee
ServiceNow Employee

Not sure if I'm too late but here's a script that may help.

Use case is creating a VTB from an incident record.  It assumes you've got an existing board called 'Major Incident VTB' (change bold text below to the board you want to copy)

 

UI Action:

Name: Create VTB

Script:

//copy board named 'Major Incident VTB'
var clonedBoard = doClone("Major Incident VTB");

//launch new board
action.setRedirectURL("$vtb.do?sysparm_board=" + clonedBoard.sys_id);



function doClone(boardName){
//find board and insert copy
var vtb = new GlideRecord('vtb_board');
vtb.addEncodedQuery('name=' + boardName);
vtb.query();
if(vtb.next()){
var origId = vtb.sys_id.toString();
var newBoard = vtb;
//append incident number to board name
newBoard.name = boardName + ' [' + current.number + ']';
//activate board
newBoard.active = true;
var newBoardId = vtb.insert();

//find all lanes associated with original board and insert copies that point to new board
var gr = new GlideRecord('vtb_lane');
gr.addEncodedQuery('board=' + origId);
gr.query();
while(gr.next()){
var newLane = gr;
newLane.board = newBoardId;
var newLaneId = gr.insert();
}
//copy the cards
var cards = new GlideRecord('vtb_card');
cards.addEncodedQuery('board=' + origId);
cards.query();
while(cards.next()){
var taskId = generateNewPrivateTask(cards.task.short_description);
var laneId = findLane(cards.lane.getDisplayValue(),newBoardId);
var newCards = cards;
newCards.board = newBoardId;
newCards.task = taskId;
newCards.lane = laneId;
var newCardId = cards.insert();
}

//copy members
var mems = new GlideRecord('vtb_board_member');
mems.addEncodedQuery('board=' + origId);
mems.query();
while(mems.next()){
var newMems = mems;
newMems.board = newBoardId;
var nowMemsId = mems.insert();
}
return newBoard;
}
return current;

}

function findLane(card,newBoard){
var gr = new GlideRecord('vtb_lane');
gr.addEncodedQuery('board=' + newBoard + '^name=' + card);
gr.query();
if(gr.next()){
return gr.sys_id;
}
}
function generateNewPrivateTask(sd){
var gr = new GlideRecord('vtb_task');
gr.initialize();
gr.short_description = sd;
var taskId = gr.insert();
return taskId;
}