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 - Write a Relationship Property into the related (Child) Item Property

biztram - Monday, September 30, 2013 1:34 PM:

Hello everyone,

i am facing the following problem:

There is the Relationship Itemtype Item Sub Folder and the "related_id"-Item Item Folder.
Both have the property sort_order (Integer).
The following method counts the sort_order for the Item Sub Folder.
Every Item Sub Folder and Item Folder has just one instance.

The sort_order Value should not only be inserted in Item Sub Folder but also in the related Item Folder.


The method is initiated by a Relationship Server Event "onBeforeAdd".

Maybe someone of you has an idea to correct my piece of code.

--------------------------------------------------------------------------------------

Dim newSortNumStr As String = Me.getProperty("sort_order","")

' if sort order already set, keep it
If newSortNumStr = "" Then newSortNumStr= "0"

Dim relSourceId As String = Me.getProperty("source_id","")
If relSourceId = "" Then Return Me 'probably not a relationship type

Dim Rels As Item = Me.newItem(Me.GetType(), "get")
Rels.setProperty("source_id",relSourceId)
Rels = Rels.apply()
Dim maxVal As Integer
Dim i As Integer
For i=0 To Rels.getItemCount() -1
Dim Rel As Item = Rels.getItemByIndex(i)
Dim sortOrder As Integer = CInt(Rel.getProperty("sort_order"))
If (sortOrder > maxVal) Then maxVal = sortOrder
Next i
'detect standard increment of 128, then correct it to +1
If (CInt(newSortNumStr) - maxVal) = 128 Then
Me.setProperty("sort_order",maxVal+1) 'increment by 1
End If

''''''''''''''''''Start of my try''''''''''''''''''
Dim thisSubFolderRel As Item = Me.newItem(Me.GetType(),"get")
thisSubFolderRel = thisSubFolderRel.apply()

thisSubFolderRel = thisSubFolderRel.getItemByIndex(0)
thisSubFolderRel.setProperty("sort_order",maxVal+1) 'increment by 1

thisSubFolderRel = thisSubFolderRel.apply()
''''''''''''''''''End of my try''''''''''''''''''''

Return Me

--------------------------------------------------------------------------------------------

Thanks in advance!
biztram