VMware {code} Community
ChrisSmith2
Enthusiast
Enthusiast
Jump to solution

How to set a condition on a portlet based on a custom property/relationship?

I'm trying to add a portlet to HostSystem that only appears if there is a relationship to one of my custom objects. However, I can't find a way to achieve this. I tried various syntaxes to add a relational constraint in "plugin.xml" but this failed to work, including one from an old post here.

I tried this on a modified "chassis-b" sample (where only the first host is assigned to a chassis, to make it easy to tell that the portlet only appears on hosts with chassis).

      <metadata>

        <propertyConditions>

          <com.vmware.data.query.CompositeConstraint>

            <nestedConstraints>

              <com.vmware.data.query.PropertyConstraint>

                <propertyName>chassis</propertyName>

                <comparator>EQUALS</comparator>

                <comparableValue>

                 <Boolean>false</Boolean>

                </comparableValue>

              </com.vmware.data.query.PropertyConstraint>

            </nestedConstraints>

            <conjoiner>AND</conjoiner>

          </com.vmware.data.query.CompositeConstraint>

        </propertyConditions>

      </metadata>

Any suggestions greatly appreciated!

Reply
0 Kudos
1 Solution

Accepted Solutions
laurentsd
VMware Employee
VMware Employee
Jump to solution

<PropertyConstraint> conditions are very particular.  I would do something like below, where you add a custom property "chassisCount" that resolves into the number of related Chassis object. You need to implement that chassisCount logic in your Data Provider

                              <conditions>

                  <com.vmware.data.query.PropertyConstraint>

                     <propertyName>chassisCount</propertyName>

                     <comparator>EQUALS</comparator>

                     <comparableValue>

                        <String>0</String>

                     </comparableValue>

                  </com.vmware.data.query.PropertyConstraint>

               </conditions>

View solution in original post

Reply
0 Kudos
4 Replies
laurentsd
VMware Employee
VMware Employee
Jump to solution

<PropertyConstraint> conditions are very particular.  I would do something like below, where you add a custom property "chassisCount" that resolves into the number of related Chassis object. You need to implement that chassisCount logic in your Data Provider

                              <conditions>

                  <com.vmware.data.query.PropertyConstraint>

                     <propertyName>chassisCount</propertyName>

                     <comparator>EQUALS</comparator>

                     <comparableValue>

                        <String>0</String>

                     </comparableValue>

                  </com.vmware.data.query.PropertyConstraint>

               </conditions>

Reply
0 Kudos
ChrisSmith2
Enthusiast
Enthusiast
Jump to solution

Thanks. This would have to be a property on the "HostSystem" VMWare-provided object, correct? Is it possible for a plugin to add such a property to the built-in objects? Is there any sample code for this? I couldn't find it in any of the samples included with the SDK.

Reply
0 Kudos
ChrisSmith2
Enthusiast
Enthusiast
Jump to solution

I worked out how to handle a property for a VMWare-provided object in my plugin, so this question is answered. Thanks for your help!

Reply
0 Kudos
laurentsd
VMware Employee
VMware Employee
Jump to solution

Good to hear.  And to answer your previous question, yes, you can use conditional properties on custom objects.

Reply
0 Kudos