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 - Rollup calculation

Yelena - Friday, January 8, 2010 9:45 AM:

I would like to calculate the value for the item property based on the values of the related item's properties after related items are added and parent item is saved.  I wrote the VB server method exetuted on the parent itemtype:

'The parent item -   Plant Feasibility
'Relationship item - Scrap REL
'The related item -  Scrap
'===================================
Dim myInnov = Me.NewInnovator()

Dim pf = myInnov.newItem("Plant Feasibility","get")
pf.setID(Me.getID())
pf.setAttribute("select","id")
Dim SRel As Item = myInnov.newItem("Scrap REL","get")
SRel.setAttribute("select","id, related_id(percent_scrap)")
pf.addRelationship(SRel)
pf = rfqpf.apply()
Dim SRItems = pf.getItemsByXPath("//Item[@type='Scrap']")
Dim percent_scrap = "0"
Dim percent_rework = "0"
Dim i As Integer
For i = 0 To SItems.getItemCount() - 1   
     Dim scrap = SItems.getItemByIndex(i).getProperty("percent_scrap")
     If Not isNothing(scrap) Then percent_scrap = val(percent_scrap) + val(scrap)
Next
Me.setProperty("percent_scrap",percent_scrap)

From this point I do not know what to do next. If I execute the method as it is OnBeforeUpdate, it updates parent's values only if  I save item twice without closing it.  If I execute the method as it is OnAfterUpdate, it shows correct value after I save the parent, but does not update the database. Obviously this is not a good solution.
Can I use the applySQL to update the table? I can not find any examples to execute SQL Update using applySQL, and anything I try produces the error message.  Could anybody  give recommendations, please?

Thank you



asha_gholve - Tuesday, May 29, 2012 9:05 AM:

HI all,

I am facing the Problem,  if anyone knows solution please guide me!!!!!!!!!!!