For some reason I cannot get my script to add a relationship.
I have a FIELD named AUTORR. It is a linked picklist.
The scripts completes without problems, but does not add a relationship. (HIGHLIGHTED)
Any ideas?
/* Create a new review record for current Change Order */
// add Change Order workflow items to the autocreated Review Record
if (item.AUTORR !== null) {
// Add all affected items in Change Order to Review Record
var reviewRecord = loadItem(item.AUTORR.descriptor.dmsID);
for (var i in item.workflowItems) {
var additemid = item.workflowItems[i].id;
var linked_item = loadItem(additemid);
reviewRecord.workflowItems.addItem({RELATED:linked_item});
}
item.relationships.addRelated({RELATED: item.AUTORR, TYPE: 'Cross-Reference', DIRECTION: 'Bidirectional'});
for (var i in item.REVIEWERS) { // Add reviewers
reviewRecord.REVIEWERS.add(item.REVIEWERS[i]);
}
}
Sten,
I do not see anything obvious wrong with your script. Can you try to comment out everything inside the condition statement, except the addRelated function and try it again? Also, is this the full script, or is there more in this script than what was posted in the thread?
/* Create a new review record for current Change Order */
// add Change Order workflow items to the autocreated Review Record
if (item.AUTORR !== null) {
// Add all affected items in Change Order to Review Record
/*
var reviewRecord = loadItem(item.AUTORR.descriptor.dmsID);
for (var i in item.workflowItems) {
var additemid = item.workflowItems[i].id;
var linked_item = loadItem(additemid);
reviewRecord.workflowItems.addItem({RELATED:linked_item});
}
*/
item.relationships.addRelated({RELATED: item.AUTORR, TYPE: 'Cross-Reference', DIRECTION:'Bidirectional'});
/*
for (var i in item.REVIEWERS) { // Add reviewers
reviewRecord.REVIEWERS.add(item.REVIEWERS[i]);
}
*/
}
First of all, that is the entire script.
I played around with uncommeting and found that adding the relationship works until I uncomment the "add workflowItem" line.
(see below)
Any ideas to why???
/* Create a new review record for current Change Order */
// add Change Order workflow items to the autocreated Review Record
if (item.AUTORR !== null) {
item.relationships.addRelated({RELATED: item.AUTORR, TYPE: 'Cross-Reference', DIRECTION: 'Bidirectional'});
// Add all affected items in Change Order to Review Record
var reviewRecord = loadItem(item.AUTORR.descriptor.dmsID);
for (var i in item.workflowItems) {
var additemid = item.workflowItems[i].id;
var linked_item = loadItem(additemid);
//ADDING RELATIONSHIP DOES NOT WORK IF NEXT LINE IS ACTIVE !!!
//reviewRecord.workflowItems.addItem({RELATED:linked_item});
}
for (var i in item.REVIEWERS) { // Add reviewers
reviewRecord.REVIEWERS.add(item.REVIEWERS[i]);
}
}
hi sten
what is the workspace type for current 'item' and 'reviewRecord' items? If they are both revisioning type, it is not possible to add the same linked_item to managed tabs of two revisioning items.
item.workflowItems already manages linked_item
vs.
reviewRecord.workflowItems wants to add it to its managed tab
Also what is the WS type of the linked_item would help too. Let us know.
Thanks,
Current item is a "Revisioning workspace"
Review record is "Basic Workspace with workflow"
The linked_item's are "Revision Controlled Workspace"
I am using scripts to spawn Review Record's from the Change Order
The end result is that I can have a single Change Order with multiple items being revisioned, and from it I can spawn multiple review records each focusing on a specific review scope.
The CO record manages the item and will perform the revisioning.
I use the "Linkeditem" tab on the review record because it allows be to cross-reference it from the revisioned item. (Linkeditemreferences tab)
All this works by hand, but I was hoping to speed up the process my creating scripts for some of the tedious work.
The reason for all these extra review records is that we have very specialied and rigid requirements to review and approval.
Are you spawning the review record in the very same script that you're trying to add linked_item to its managed tab? This is not possible in today's scripting capabilities - the review record hasn't been committed and as such cannot add items to its tabs because the tabs don't exist yet. Let me know,
No that is not it. I have had issues with that in the past. It usually generates a bunch of null errors.
In this case I have split the task up to two scripts that I have to manually execute to get around that little nuisance.
At the point where I execute this particular script all items have been created.