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

[SOLVED] Sum same property from different lookups in another property

Hi community!

First time posting, I'm starting to getting in touch with the API and VBScript with M-Files.
I have a vault which has 2 object types that are making me struggling : Invoices and Articles

To be short, every Article(1098) has an Amount(1038) and every Invoice can contain multiple Articles.
The invoice has a total amount value and I would like to calculate it by summing every Amount in the different Articles.

I started by looking at the different topics and I got to this :


' Declare our variables.
Dim objArtTypedValue, objArtPropertyValues,  objArtObjVer, strAmount, totAmount,

' This is the typed value Lookups collection of the Article class from the current object's properties.
Set objArtTypedValue = PropertyValues.SearchForProperty(1098).TypedValue.GetValueAsLookups()

' Is this really a collection/array? Let's try some black magic...
For Each article in objArtTypedValue

' ObjVer object creation to load the Article's properties
Set objArtObjVer = CreateObject("MFilesAPI.ObjVer")
objArtObjVer.SetIDs article.ObjectType, article.Item, article.Version


' Load the Art property values from the vault (for this ObjVer).
Set objArtPropertyValues= Vault.ObjectPropertyOperations.GetProperties(objArtObjVer, True)

' Now get the Amount.
strAmount = objArtPropertyValues.SearchForProperty(1038).TypedValue.DisplayValue

'And as "+=" doesn't work let's try it the old school way
totAmount = totAmount + strAmount

Next

' Output the total
Output =  totAmount 


But I'm not really getting it working, here is an error message :

Montant calcul?, PropertyDefCalculatedValue, 16, Non trouv?. (0x8004000B) //Calculated amount, PropertyDefCalculatedValue,16, Not found

Which refers to the following line :
Set objArtPropertyValues= Vault.ObjectPropertyOperations.GetProperties(objArtObjVer, True)

Like if those lines weren't working :
Set objArtObjVer = CreateObject("MFilesAPI.ObjVer")
objArtObjVer.SetIDs article.ObjectType, article.Item, article.Version


I tried to debug by getting the article.Item/Version/ObjectType properties by throwing an error, and looks like my foreach works at this point and the problem really looks like to be further.

Maybe someone of you has an idea on the way to do? Maybe the For Each shouldn't work like this?

Thanks in advance for your time and have a nice day

Manuel Cabras
Altern8 SA - www.evok.ch
Parents Reply Children
No Data