To automate some work of mine, i'm diving into javascript and the smartsheet-api, ... I wrote a script that sets up a workspace by copying the whole workspace with a new workspacename. Sharing the workspace to different people, share individual sheets to other people, generate some links to and from the newly generated sheets, ...
Some of these actions weren't as easy, as I thought, ... Nevertheless, at the end of the day it worked.
But now I found out, that the workflows of the sheets weren't copied, ... there are no workflows in the sheets copied.
I'm using node as my javascript-runtime-environment.
//-------------------------------------------------------------------------------------
// prepare copying the workspace
// ------------------------------
var body = { newName: workspaceName }; // store the workspaceName from the function-parameters in the body-object
var params = { include: "all, rules, ruleRecipients", skipRemap: "" }; // set parameters
var options = { workspaceId: sourceWorkspaceID, body: body, queryParameters: params }; // create the options-object with all the settings above
//--------------------------------------------------------------------------------------
try { // Try copying workspace
copiedWorkspace = await ss.workspaces.copyWorkspace(options); // ---------------------
console.log('setupTheWorkspace: Workspace wurde kopiert.');
} catch (e) {
console.log('setupTheWorkspace: Workspace konnte nicht kopiert werden.');
console.log(e);
The code above shows the way, I do the copying. First I tried it with only "all" as the include-param, then I added "rules, ruleRecipients" to the include-param, but to no avail.
What do I have to do, that the worklows of the sheets are copied by copying the workspace?
A few comments:
The Smartsheet API docs for the Copy Workspace operation describe the all
value of the include
parameter as deprecated. It's generally recommended to avoid using anything that's marked as 'deprecated'.
The value of the include
parameter should not contain any spaces. I suspect this is the source of your issue -- i.e., Smartsheet is not recognizing values that contain a leading space -- e.g., ' rules'
or ' ruleRecipients'
-- and therefore is ignoring them.
If I'm understanding the docs correctly, you only need to specify the skipRemap
parameter if you want to NOT remap certain references in the newly created workspace. Specifying that parameter with an empty value doesn't make sense -- I'd suggest you remove it if you're not going to specify a value for it.
Here's the line from your code that reflects these recommendations:
var params = { include: "rules,ruleRecipients" };
Note: Be sure to add additional values to the include
parameter if you want other stuff (besides workflows) to be copied to the new workspace. The docs contain a list of all valid values. And be sure to NOT include any spaces in the comma-delimited list of values.
Here's some sample code that successfully copies a workspace (and specifies all values of the include
parameter).
// Specify new workspace name
var body = {
newName: 'My New Workspace'
};
// Set elements to copy
var params = {
include: 'attachments,cellLinks,data,discussions,filters,forms,rules,ruleRecipients,shares'
};
// Set options
var options = {
workspaceId: 6192537502279556,
body: body,
queryParameters: params
};
// Copy workspace
smartsheet.workspaces.copyWorkspace(options)
.then(function(copiedWorkspace) {
console.log(copiedWorkspace);
})
.catch(function(error) {
console.log(error);
});