Scripting: Create Linked Item in proj management -tab of a certain Item

Scripting: Create Linked Item in proj management -tab of a certain Item

Toon.Broothaerts
Advocate Advocate
2,635 Views
15 Replies
Message 1 of 16

Scripting: Create Linked Item in proj management -tab of a certain Item

Toon.Broothaerts
Advocate
Advocate

So let me sketch the situation: I have two workspaces WS1 and WS2. If an item enters a certain state in WS1, an item is created in WS2. This newly-created item should be linked in the Project Management -tab of a certain item in WS1.

 

How do I define this? Is this possible via scripting or should I need to look at other options?

 

Thanks in advance,

Toon


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Replies (15)
Message 2 of 16

tony.mandatori
Autodesk
Autodesk

You can create the new item with the createNewItem library script.

 

To add to the pm tab, you can use something like this:

item.project.addTask(itemX);

Does that help? 

0 Likes
Message 3 of 16

Toon.Broothaerts
Advocate
Advocate

Creating the item is already in place. It's the linking that I want to solve.

 

Doesn't the following code just create the link in the Project Management of the current item?

item.project.addTask(itemX)

 


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Message 4 of 16

philipfrench
Collaborator
Collaborator
Accepted solution

Not clear your issue, and why Tony's answer doesn't solve it for you?

In your WS1 action script, have something like this...

 

var newItem = createNewItem(... etc in WS2);
item.project.addTask(newItem);

 

Is that not what you need?

0 Likes
Message 5 of 16

tony.mandatori
Autodesk
Autodesk
Accepted solution

Yes,

 

When you create the new item (WS2), you can add a linking picklist to the parent item (WS1). Then, using an on create script on the new item (WS2), you can load the other item (WS2 - item.picklist) and add it to the PM tab of the related item (WS1).

 

So WS2 is linked to the PM Tab of WS1 and WS2 has a linking Picklist on the details tab pointing to WS1.

 

Is that what you're after?

0 Likes
Message 6 of 16

Toon.Broothaerts
Advocate
Advocate

Hi Philip, nice to hear from you again.

 

I'm not 100% sure that what you guys are saying will solve the problem. I think what you and Tony described, will create the Item Link in the active item (in which this script was written).

 

The new item from WS2 needs to be Linked to a fixed item of WS1.

 

Let me explain:

WS1= Development Projects

WS2= Technical Verification Projects

 

When a certain Development Project "D-00761" in WS1 enters a certain state, a Technical Verification Project "TV-00761" is created in WS2.

 

I want to link this TV-00761 to a fixed Development Project "D-TV-2020", where all TV projects who are created out of a D project will be linked to.

 

Am I still making sense? Thank you guys, for taking time to help me out.


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Message 7 of 16

Toon.Broothaerts
Advocate
Advocate

Hey, this option might work. I will explore the "linking picklist", I have never used it before.

 

Tony, do you maybe know some documentation which could explain the way Linking Picklists work?

 

Thanks again!


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Message 8 of 16

tony.mandatori
Autodesk
Autodesk

A linking picklist is just a workspace picklist. You can set the value programmatically using a string that matches the entry. I usually use the descriptor as the text: as long as you provide the exact text of the descriptor, you can set the value of the picklist.

 

As a side note, after you set the value, you can pick up attributes on the related item as well - this is powerful as you don't need to find the item to set the picklist.

 

http://help.autodesk.com/view/PLM/ENU/?guid=GUID-7EB1C249-A3F4-4B52-8829-B03D276AF899

0 Likes
Message 9 of 16

sven.dickmans
Autodesk
Autodesk
Accepted solution

If you add a linking pick list field in your WS2 which links to WS1 and name this field "DEVELOPMENT_PROJECT", then you can easily store the link in this field upon creation like this:

var newItem = createNewItem("WS2");
newItem.DEVELOPMENT_PROJECT = item;

 

0 Likes
Message 10 of 16

bryce_crawford
Advocate
Advocate

I do this all the time, but it's not as straight forward as it sounds. I believe that if you create an item in WS2 that you want to link to a record that creates it in WS1, you can't do it in the same script. The problem is that the item in WS2 does not exist until the script finishes so you can't actually link it to WS1 in the script where you create it. I have gotten around this by creating an on-save script in WS2 that reads a field containing the record from WS1. This lets you load the record in WS1 that created the item in WS2. You can then set a picklist in WS1 to the item you created in WS2. It is something like this:

 

Script in WS1

newItem = createnewitem(WS2)

newItem.WS1RECORD= item

 

On-save script in WS2

WS1item = load(item.WS1RECORD)

WS1item.WS2ITEM = item

 

Message 11 of 16

dave_marshall_d11
Participant
Participant
Accepted solution

The way i do it is have a field that links to the main workspace. Then on the workflow action of "Create" or whatever your first transition is called I look to see if the field is filled in (actually mandatory on creation) and then write to the project

 

 

if (item.RELATED_NPI_PROJECT !== null)
{
item.RELATED_NPI_PROJECT.project.addTask(item);
}

0 Likes
Message 12 of 16

Toon.Broothaerts
Advocate
Advocate

Hi @dave_marshall_d11,

 

And the field is a linking picklist with field ID "RELATED_NPI_PROJECT"?

 

I found this works quite good. The only thing I'm missing here is: I would like to link to a pre-defined project in the workspace, how can I make sure it links to that project? (how can I hard code it?)


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes
Message 13 of 16

dave_marshall_d11
Participant
Participant

And the field is a linking picklist with field ID "RELATED_NPI_PROJECT"?  Yes

 

when you spawn the WS2 item you can state the linking field to be the WS1 item.

 

In the case using the field names I've stated,

var newProperties = [];
newProperties.RELATED_NPI_PROJECT = item;
*****

****

******
createNewItem('WS_****', newProperties);

 

obviously depends on the how you spawn your items

hope that makes sense

 

0 Likes
Message 14 of 16

dave_marshall_d11
Participant
Participant

Looking at the last message you sent me, do you need a space after the - so the text ends ......  all - ';

 

depends on your settings

 

 

0 Likes
Message 15 of 16

dave_marshall_d11
Participant
Participant

reposted so it is in reply to you / not me 😀

 

Looking at the last message you sent me, do you need a space after the - so the text ends ......  all - ';

 

depends on your settings

0 Likes
Message 16 of 16

Toon.Broothaerts
Advocate
Advocate

Yes I believe it had something to to with the String. It's solved now and works like a charm, thank you!


Toon Broothaerts

If my answer solved your question, please mark it as 'solution'. Else, feel free to contact me!
0 Likes