How do you Copy a Freeform Visual Task Board?

Danielle Shingi
Tera Contributor

I used this script from a previous thread. But when I click the button it doesn't copy the board. I currently have it on the form view of an already created VTB but it doesnt work. 

https://community.servicenow.com/community?id=community_question&sys_id=19c44be9dbd8dbc01dcaf3231f96...

 

var VTBCloneUtil = Class.create();
VTBCloneUtil.prototype ={
initialize: function() {
},
cloneBoard: function(existingBoard) {
// Let's get the board first
var clone = new GlideRecord("vtb_board");
clone.initialize();
clone.name = "Copy of" + existingBoard.name;
clone.table = existingBoard.table;
clone.field = existingBoard.field;
clone.filter = existingBoard.filter;
// Add any other fields to clone here

var cloneSID = clone.insert(); // This will clone the lanes of the board

if (cloneSID) {
this.cloneLanes(cloneSID, existingBoard.sys_id);
}
return clone;
},
cloneLanes: function(newSID, existingSID) {
var newLane = new GlideRecord("vtb_lane");

var existingLane = new GlideRecord("vtb_lane");
existingLane.addQuery("board" , existingSID);
existingLane.insert();

while (existingLane._next()) {
newLane.initialize();
newLane.name = existingLane.name;
// Add any other fields and values here
newLane.board = newSID;
newLane.insert();
}
//choose to return something
},
type: 'VTBCloneUtil'
};

2 REPLIES 2

Barbara L - Gli
Tera Guru

I could get it to work in my Madrid dev, so it could be a compatibility problem or it could be some small error. Did you see anything at all happen clicking the UI Action?

And just to clarify, your UI Action that is not client-callable contains the following code from that thread you mentioned?

// Clone the board

var originalBoard = current.name;

var clonedBoard = (new VTBCloneUtil()).cloneBoard(current);

// Redirect to the new board

action.setRedirectURL(clonedBoard);

gs.addInfoMessage(gs.getMessage("Cloned from {0} board", originalBoard));

And the code you pasted above exists in a Script Include called "VTBCloneUtil"?

Danielle Shingi
Tera Contributor

Yes, that resolved my issue. I now need help copying the members and the labels. Is that possible? I realized I was putting my UI action code in the Script Include section.