Developer Forum »
OnBeforeUpdate - retrieve objects added
9 posts

Hello

In the OnBeforeUpdate method of a custom webnodes class I need to retrieve the objects that are currently being added to a Content children property (RelatedProducts).
I thought I could do it like this (I've done this successfully for string properties, only with GetDataValue instead of GetDataValueRelation):

IDataValue dValueRelatedProducts = GetDataValueRelation(MyProduct.PropertyIdRelatedProducts);

if (dValueRelatedProducts.Changed)
{
    List<MyProduct> relatedProducts = (List<MyProduct>)dValueRelatedProducts.ObjectValue;
}

But ObjectValue throws an exception:

This property is not supported by this datavalue type.
   at WAF.Data.DataValue.NodeRelationsDataValue.get_ObjectValue()
   at WAF.Engine.Content.....OnBeforeUpdate() in .....
   at WAF.Engine.Content.ContentBase.UpdateChanges(Boolean updateChangeDate, Boolean invokeEventMethods, Boolean queChangesForIndexing)
   at WAF.Engine.Content.ContentBase.UpdateChanges(Boolean updateChangeDate, Boolean invokeEventMethods)
   at WAF.Engine.Content.ContentBase.UpdateChanges()
   at WAF.Engine.Presentation.Web.WMSearchAndSelect.onFound(WorkflowMethod invoker)
   at WAF.Engine.Workflow.WorkflowMethodCaller.callMethod_ExecuteCode(Object sender, EventArgs e)

What am I doing wrong? I'm only interested in the values added in the current update, not all values of the property.

181 posts

Hi!

As you have seen, relation data values don't support ObjectValue. The easiest way would be to cast the IDataValue to NodeRelationsDataValue, and then call the GetAdded() (and GetRemoved()) method on that object to get the added relations.

Let me know if you get it to work. If not, I can create an example.

9 posts

It works! Thank you!

1