This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Relate a created Item to an Item type as a relatedItem on saving the Item.

meenu - Monday, January 21, 2013 3:20 AM:

Hi,

     I have an Itemtype and a relationship to the Itemtype ,Document as the related Item. Now what I' m doing is without using 'create' or 'pick ' options, I' m trying to relate the documents(At the time of creation) to my Item type by calling a method on OnAfterAdd.

The code I' m using is:

Dim inn As innovator = Me.getInnovator()
Dim dept As String = Me.getPropertyAttribute("team_id","keyed_name")

If dept="Design Engineering" Then

Dim rel_item As Item = Me.newItem()
   rel_item.loadAML("<Item type='Dept' action='get' Select ='name'>"+

                        "<name Condition='like'>Design Engineering</name>"+
                        "<Relationships>"+
                        "<Item type='DeptDocs' action='add'><related_id><Item type='Document'   action='get' select='name'> <name Condition ='like'>Des*<Item></related_id> </Item>"+
                        "</Relationships>"+
                        "</Item>"" )

Dim result As Item = rel_item.Apply()

End If

Here on save of a document, based on the condition I' m trying to relate this document to the Item type' s  relationship(As per the conditions) as  a relatedItem. 

But this code is doing nothing. Anything I missed ? Please help me .

Thank you/ M.K



vasant - Monday, January 21, 2013 6:07 AM:

Hi Mk,

Code as mentioned below:

Dim inn As innovator = Me.getInnovator()
Dim dept As String = Me.getPropertyAttribute("team_id","keyed_name") 
If dept="Design Engineering" Then 
Dim rel_item As Item = Me.newItem()
   rel_item.loadAML("<Item type='Dept' action='edit' where="[Dept].name='Design Engineering'">"+
                                "<name>Design Engineering</name>"+
                        "<Relationships>"+
                                     "<Item type='DeptDocs' action='add'>"+
                                           "<related_id>"+
                                                "<Item type='Document' action='get' select='name'><name condition ='like'>Des*<Item>"+
                                           "</related_id>"+
                                     "</Item>"+
                        "</Relationships>"+
                    "</Item>")
Dim result As Item = rel_item.apply() 
End If
 
Thanks & Regards,
Vasant Padhiyar



meenu - Tuesday, January 22, 2013 12:52 AM:

Thank you Vasant,

Syntax of 'where' clause is creating problems.  

And, can I add multiple related items at a time saying like: <name condition ='like'> *doc* </name>.  Will it add more than one related Item?

Thanks for your help.

M.K