Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.

 

How do you explicitly set a Dynamic Property to a null value?

Vote:
 

What if I want a Dynamic Property to have a null value at a certain point?  If I enter nothing, then the value "full upward" to its parent.  In most cases, this is what you want.  But in this case, I want to explicitly set it to a null value.

My property, in this situation, is a Link Collection.  The only way this returns null is to not add any links to it.  But then it just pulls its parent value.

#51120
May 25, 2011 0:41
Vote:
 

Hi Dean!

As you describe the default behaviour is to have defined/not defined for a dynamic property and go up in the parent chain until we find a defined value. If you want to have a "null from this point" value you probably need to create a custom property that has the posibility to store a value that is treated as null in your code. Since the Link Collection uses xml to store and load it's value I think that this can be a bit tricky but perhaps you can override the set and get value methods for the Link Collection and same some "magic" xml for a null value, otherwise just call the base implementation.

Another alternative could be to just create another property that holds a "defined/not defined" state and create a wrapper that takes both properties into consideration.

None of the alternatives are very nice but since EPiServer does not have built in support for the moment I think you are stuck with making some kind of work around.

Regards
Linus Ekström
EPiServer Development Team 

#51124
May 25, 2011 7:23
Vote:
 

You could define your link collection property on a page type and use a dynamic property to point to different instances of that page type. When you want the empty link collection you simply redefine the dynamic property to point to a page which has an empty link collection. Still not pretty, but you don't have to override any code and/or create a custom property type.

#51130
May 25, 2011 9:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.