having 3 days of trouble with this. Trying to pass filepaths from an array and add them to cmd object which should then copy them to collection. What seems to happen is that when the cmd is run, each path is added twice - which results in errors that 'file already added to collection' :
Any ideas would be helpful.
var groupPathsARR = []
for (var GROUPkey in tokensOBJ) {
if (tokensOBJ.hasOwnProperty(GROUPkey) && counter < 10) {
groupPathsARR = tokensOBJ[GROUPkey];
for (var i = 0; i < groupPathsARR.length; i++) {
cmd.AddFile(groupPathsARR[i]);
}
copyVirtuallyToCOll = 1;
if (copyVirtuallyToCOll) {
cmd.RunCommand('COPY TO coll://DUPES ');
}
}
counter++;
// cmd.ClearFiles();
}```
In scripts add-ins and button scripts, you can get a Command object from the entry point parameter.
That cmd object already has selected files "within".
So, if you're using that cmd and do not ClearFiles before running a command, it will apply to both the files selected and the ones you added.
If you do not want that, either clear files before adding new ones or get a new command object (DOpus.Create.Command())
I'm wondering - since creating the object myself and may be prone to errors, I wonder if the '' in the string might cause issues (maybe should be escaped i.e. "\") . However that would give different error I would assume)
Here is a schema of my obj from which I get the data:
var cmd2 =DOpus.Create.Command()
var groupPathsARR = []
for (var GROUPkey in tokensOBJ) {
if (tokensOBJ.hasOwnProperty(GROUPkey) && counter < 5) {
groupPathsARR = tokensOBJ[GROUPkey];
for (var i = 0; i < groupPathsARR.length; i++) {
cmd2.addFile(groupPathsARR[i]);
}
copyVirtuallyToCOll = 1;
if (copyVirtuallyToCOll) {
cmd2.RunCommand("Copy TO coll://DUPES");
}
}
counter++;
}
Basically, because you're adding new files to the Command object in each iteration and then executing the command but with all the accumulated files, not just the ones you just added. This inevitably makes you repeat some copies. RunCommand() doesn't "clear" the files loaded into the Command object.
With something like this, you should be fine.
var cmd2 =DOpus.Create.Command();
var copyVirtuallyToCOll = 1;
var groupPathsARR = [];
for (var GROUPkey in tokensOBJ) {
if (tokensOBJ.hasOwnProperty(GROUPkey) && counter < 5) {
groupPathsARR = tokensOBJ[GROUPkey];
for (var i = 0; i < groupPathsARR.length; i++)
cmd2.addFile(groupPathsARR[i]);
}
counter++;
}
if (cmd2.filecount && copyVirtuallyToCOll)
cmd2.RunCommand("Copy TO coll://DUPES");