Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding relationship through script

6 REPLIES 6
Reply
Message 1 of 7
sten
439 Views, 6 Replies

Adding relationship through script

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]);
  }
}

Tags (1)
6 REPLIES 6
Message 2 of 7
jared.sund
in reply to: sten

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]);
  }
  */
}

Jared Sund
Sr. Product Line Manager, Product Lifecycle Management
Autodesk, Inc.
Message 3 of 7
sten
in reply to: jared.sund

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]);
}

}

Message 4 of 7
gasevsm
in reply to: sten

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,

 


Martin Gasevski | Fusion 360 Team Product Manager
Message 5 of 7
sten
in reply to: gasevsm

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.

Message 6 of 7
gasevsm
in reply to: sten

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,


Martin Gasevski | Fusion 360 Team Product Manager
Message 7 of 7
sten
in reply to: gasevsm

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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report