Question Chris Bransden · Apr 19, 2017

Programmatically adding relationships to object instances

Hi!

I'm trying to insert a relationship from a parent object instance to a child object instnace programmatically. Ie, i want to do:

Do parentObject.childRefProperty.Insert(chilDobject)

where childRefProperty is defined by a string. I feel this should be achievable with $PROPERTY and/or $METHOD or maybe something in $SYSTEM.OBJ.*, but can't quite figure it out. Anyone know?

Cheers :)

Chris

Comments

Sean Connelly · Apr 19, 2017

Have you tried...

set p=$property(parentObject,"childRefProperty")
do p.Insert(childObject)
0
Chris Bransden  Apr 19, 2017 to Sean Connelly

Perfect, thanks! I'd actually already tried this but had some other bug in my code that meant me think it wasn't working - I looked more carefully and figured it out :)

0
Sean Connelly · Apr 19, 2017

I just tried the above out and it works.

You can do it more succinctly, but you must use "set" on $property as a "do" will throw a compile error for some reason...

set sc=$property(parentObject,"childRefProperty").Insert(childObject)
0