Hi!
Is there a better way to get package (or package list) the workflow belongs to in the script (which is a part of the same workflow), rather than iterating over all server packages and finding specified workflow in them?
Thank you.
Some code sample. I have updated his from some code I worte so please test it. You need to pass it the workflowId you are looking for.
var allPackages = Server.findAllForType("Package");
var packagesForWorkflow = new Array();
for each (var pack in allPackages) {
for each (var wf in pack.workflows) {
if (wf.id == workflowId) packagesForWorkflow.push(pack);
}
}
No, neither in the vCO Scripting API nor the REST API 😞
Cheers,
Joerg
Also this workflow could be in 0 to n packages.
So the resulting array could contain 0 to N entries .
After investigating a little bit, I found, that there's no easy way to get the list of all installed packages (or maybe I haven't dug deep enough?). If there would be such a way, then I would just iterate over all packages, looking for their workflows having same ID as workflow I am currently running ("workflow.currentWorkflow.id") as I assumed in my first post. But it looks, that to do that I need to register local vCO instance as its own RemoteServer and then I get "RemoteServer.findAllPackages()" method.
That is getting too complicated and time consuming (RemoteServer registration can take minutes).
So I probably will use another approach: in a workflow I'll create an attribute with "Package" type pointing to the package containing this workflow. As I checked, this approach survives "package export/package delete with content/package import" cycle, so after package import attribute still holds proper reference to the package which was just imported.
Can anybody suggest better way to achieve it?
If you have to do this on remote vCo server then you can use the REST plug-in.
HTTP get on /packages/ gets all the package list
/package/packageName/ get all the content of a workflow.
You will get JSON strings. You can convert these to object doing var pckgDetail = eval(jsonString);
Here is an example when getting the package content
var workflows = pckgDetail.workflows;
for (var w = 0; w < workflows.length; w++) {
var workflow = workflows[w];
var attributes = workflow.attributes;
for (var j = 0; j < attributes.length; j++) {
var attribute = attributes[j];
if (attribute.name == "id") {
if (attribute.value == workflowId) {packageArray.push(pckgDetail.name);
}
}
}
}
If I understand correctly then I can use REST plug-in of vCO server to make queries against itself?
If so, then this would be viable solution.
I will try this, thanks.
If I recall well there is a scripting API for packages so you can list the details of these without using REST. This of course only works if you use a single vCO server.
Some code sample. I have updated his from some code I worte so please test it. You need to pass it the workflowId you are looking for.
var allPackages = Server.findAllForType("Package");
var packagesForWorkflow = new Array();
for each (var pack in allPackages) {
for each (var wf in pack.workflows) {
if (wf.id == workflowId) packagesForWorkflow.push(pack);
}
}
Exactly what I need.
Thank you.
I didn't expect that this method can return packages.