Harsha - Tuesday, August 21, 2012 4:16 AM:
Hi
I'm trying to add a relationship between item_type1 & item_type2 by following code.
Dim myInnov As Innovator = Me.getInnovator()
Dim ItemTypeID As String = Me.getID()
'
Dim sourceItem As Item = myInnov.newItem("item_type1", "get")
sourceItem.setAttribute("id", ItemTypeID)
sourceItem.setAttribute("select", "id,item_number,year")
sourceItem = sourceItem.apply()
'
Dim relItem As Item = Me.newItem("relationship_name","add")
relItem.setProperty("source_id",Me.getID())
relItem.setAttribute("select","schedule_id,related_id(source_id,item_number,year)")
relItem = relItem.apply()
If (relItem.isError) Then
Return relItem
End If
Dim scheduleItem As Item = relItem.createRelatedItem("item_type2","add")
scheduleItem.setProperty("schedule_id", Me.getProperty("schedule_id","")
scheduleItem.setProperty("remarks", Me.getProperty("remarks","")
item_number & year are the properties of item_type1 & schedule_id & remarks are the properties of item_type2.
1.I'm not getting related item under relationship tab & How to get a related item under relationship tab..
2.Related item should be created under relationship tab.But in my case its creating a new item in item_type2
vasant - Tuesday, August 21, 2012 5:45 AM:
Hi Harsha,
You are not setting the Value of Property "related_id", which is mandatory while creation of Relationship between two ItemTypes.
Please use any one of following code to Create Relationship:
1. If Related Item Exists
Dim myInnov As Innovator = Me.getInnovator()
Dim source_id As String = Me.getProperty("source_id")'id of Source Item
Dim related_id As String = Me.getProperty("related_id")'id of Related Item
Dim relItem As Item = Me.newItem("relationship_name","add")
relItem.setProperty("source_id",source_id)
relItem.setProperty("related_id",related_id)
relItem = relItem.apply()
Return Me
2. If Related Item doesnot Exists
Dim myInnov As Innovator = Me.getInnovator()
Dim source_id As String = Me.getProperty("source_id")'id of Source Item
Dim relatedItem As Item = Me.newItem("itemtype2","add")
relatedItem.setProperty("schedule_id","")
relatedItem.setProperty("remarks","")
relatedItem=relatedItem.apply()
Dim related_id As String = relatedItem.getProperty("id")'id of Related Item
Dim relItem As Item = Me.newItem("relationship_name","add")
relItem.setProperty("source_id",source_id)
relItem.setProperty("related_id",related_id)
relItem = relItem.apply()
Return Me
Hope it helps..
Thanks & Regards,
Vasant Padhiyar
Harsha - Wednesday, August 22, 2012 1:12 AM:
Thank you Vasant. The relationship has created and able to add the items.
But Item_type1 should be able to display the items under the relationship in my case it is 'relationship_name'.
Actually based on a drop down selection in Item_type1's form the items of Item_type2 should be listed under 'relationship_name' ,mean the Items that displayed should match for the drop down selection.
I can select the created items using 'pick related', but I should be able to select from the list of items that are displayed under relationship tab. Is there any way to display the created items under the relationship tab without selecting using 'pick related'?
Thank You,
Harsha
Harsha - Thursday, August 23, 2012 12:42 AM:
Hi ,
I' m able to add only one related item row under the relationship tab, How to add multiple related Items to the relationship tab at a single time?
Any loop required to do this? Please Help me.
Thank You,
Harsha
vasant - Thursday, August 23, 2012 6:39 AM:
Hi Harsha,
Yes, you can add multiple related items using loop..
Sample Code:
Dim myInnov As Innovator = Me.getInnovator()
Dim source_id As String = Me.getProperty("source_id")'id of Source Item
Dim RelatedIds() As String = {"5F9308DF3AFB4BC381D46E0D9A83D3A5", "5F9308DF3AFB4BC381D46E0D9A83D3A5", "5F9308DF3AFB4BC381D46E0D9A83D3A5"}
For Each related_id As String In RelatedIds
Dim relItem As Item = Me.newItem("relationship_name","add")
relItem.setProperty("source_id",source_id)
relItem.setProperty("related_id",related_id)
relItem = relItem.apply()
Next
Return Me
Hope it helps..
Thanks & Regards,
Vasant Padhiyar
Harsha - Thursday, August 23, 2012 7:19 AM:
HI Vasant ,
Many thanks for your help.I will try this, But the problem is I should create and add the related Items at a time. I can' t add the existing related Items.
So I may not get the ids of related Items while doing creation and adding at a time. I am still trying to make this happen.Need help.
Thank you
Harsha