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 - Source Item' s property value on Related Item

ergr - Thursday, July 4, 2013 3:18 AM:

Hi,

 What is the easier way to get the source item' s property value on the related item? 

For ex: ItemTpye1(source item) has a field and a relationship, where Itemtype2 is the related item. Itemtype2 has a field. I can only 'Create Related' from Source Item. When I create a related item and save then its field should get the same value what source item' s field have. 

 

For this I have created a ServerEvent and added under Itemtype2 with OnBeforeAdd. The way I tried is, I added a property on Relationship Itemtype data typed as Foreign pointing to SourceItem' s property. And I' m setting this property value to the related item's field.

 

Dim id As String = Me.getID()

Dim relitem As Item = inn.newItem("RelationshipItem","get")

relitem.setAttribute("where","[RelationshipItem].related_id = '"+id+"' ")

Dim res As Item = relitem.Apply()

Me.setProperty("stage_id",res.getProperty("test","")) 

 

OnBeforeAdd it says 'Not A single Item' , OnBeforeUpdate it is working. Where I need to save the Source Item first to add the relationship and two times save of related item.

Is there any other best way of doing this?

Thank You 



zahar - Thursday, July 4, 2013 4:24 PM:

You cab set onAfterAddonAfterUpdate on Relationship and write following code:

Dim source as Item = Me.getPropertyItem("source_id")

Dim related as Item  = Me.getRelatedItem()

Dim update as Item = inn.newItem(related.getType(), "merge")

update.setAttribute("version", 0) //if your item type is versionable

update.setAttribute("serverMethod", 0) //if you prefer not execute any servermethods on related item update

update.setProperty("stage_id",source.getProperty("test","")) 

Dim result Item = update.apply()