2 Replies Latest reply on May 29, 2015 8:42 AM by Dan Chan

    Unable to create an If, Then condition for a Template Rule

    Peter Stanbridge

      Hi everyone,

       

      I have a requirement to automate the creation of a number of Component Templates on a regular basis.  It's taken some time but I've managed to use a number of unreleased commands to get 99% there.  In fact, I'm stuck on the final hurdle.

       

      I need to create the following IF THEN rule within the Template.  I can create both conditions and add them to the Template Rule individually.  I'm struggling however to add them as part of an IF THEN condition.

       

      IF

      (COMPONENT PROPERTY)

      ??TARGET.<PROPERTYCLASS X>?? != "Instance=://SystemObject/<PROPERTYINSTANCE>"

      THEN

      (CONFIG OBJECT)

      "Registry Value:<REGKEY>" exist

      END

       

      I think I may need to use the unrelesed blcli command below:

       

      Condition createIfCondition $subCond (Arg type: java.util.List) - This requires at least 2 conditions in a list.

       

      I have the conditions, I just can't work out how to get them into a list.  I've tried using Utility objectToList (noArgs) but maybe I'm not quite using it right.

       

      Any ideas?  This should be the easy part.  Feel free to suggest a different method if there's an easier way.

       

      Thanks,

      Pete

       

      PS.  I'll try and attached the current script later but I can't retrieve the script at present

        • 1. Re: Unable to create an If, Then condition for a Template Rule
          Peter Stanbridge

          Hi, Here's the script as it stands.  "function buildifcond" is the area I'm having issue with.  Note: I have a lot of echos in there at the moment for debugging purposes.

           

          blcli_setoption roleName BLAdmins

          blcli_setoption serviceProfileName defaultProfile

           

          ## VARIABLES TEMPORARILY HARDCODED FOR TESTING.  YOU WILL NEED  TO UPDATE IF YOU WISH TO TEST THIS ##

          #Template Variables

          templateGroupName="/Migration"

          templatename="WORD_V_3"

           

          #Rule Variables

          ruleGrpName="TEST RULE GROUP"

          ruleName="testifWORD_V_3"

          description=""

          refNumber=""

          isCommentedOut="false"

          notes=""

           

          #Property Condition Variables

          propertyReference="Class://SystemObject/Component"

          property="??TARGET._SERVERPROFILE.SERVERPROFILES_V_3._WORD_V_3??"

          value="Class://SystemObject/WINDOWS/OPTION/OPTION_V_3/WORD_V_3/_empty"

           

          #Server Object Condition Variables

          type="REGISTRY VALUE"

          path="HKEY_LOCAL_MACHINE\SOFTWARE\Packages\??TARGET._SERVERPROFILE.SERVERPROFILES_V_3._WORD_V_3._SIGNATURE??"

          cardinaryOption="Must Exist"

          asserAttributeName="Path"

          operator="does not equal"

          attributeValue=""

           

          ## THIS WORKS ##

          function lookuptemplate {

          echo "Looking Up Template"

          echo "\\n"

          blcli_execute TemplateGroup groupNameToDBKey $templateGroupName

          blcli_storeenv GROUPDBKEY

          echo "\\n"

          blcli_execute Template findByGroupAndName $GROUPDBKEY $templatename

          blcli_execute Utility storeTargetObject template

          blcli_execute Template getAssociatedComponentSubclass

          blcli_execute Utility setTargetObject

          blcli_execute Utility storeTargetObject psc

          echo "\\n"

           

          }

           

          ## THIS WORKS ##

          function buildserverobjcond {

          echo "Building Server Object Condition"

          echo "\\n"

          blcli_execute Condition createServerObjectCondition "$type" "$path" "$cardinaryOption" "$asserAttributeName" "$operator" "$attributeValue" NAMED_OBJECT=psc

          blcli_execute Utility storeTargetObject servobjconditionObject

          echo "\\n"

          }

           

          ## THIS WORKS ##

          function buildpropertycond {

          echo "Building Property Condition"

          echo "\\n"

          blcli_execute Condition createPropertyCondition "$propertyReference" "$property" "does not equal" "$value"

          blcli_execute Utility storeTargetObject propconditionObject

          echo "\\n"

           

          }

           

          ## THIS IS THE SECTION I CANT GET TO WORK ##

          function buildifcond {

          echo "Building If Condition"

          echo "\\n"

          echo "\\n Get servobjconditionObject"

          blcli_execute Utility setTargetObject servobjconditionObject

          echo "\\n Export to list"

          blcli_execute Utility objectToList

          echo "\\n Get propconditionObject"

          blcli_execute Utility setTargetObject propconditionObject

          echo "\\n Export to list"

          blcli_execute Utility objectToList

          echo "\\n Print List"

          blcli_execute Utility listPrint

          echo "\\n"

           

          }

           

          ## TO BE USED TO TEST THE CONDITION IF REQUIRED##

          function addserverobjcond {

          echo "Adding Server Object Condition Rule"

          echo "\\n"

          blcli_execute Template addRuleWithCondition NAMED_OBJECT=template "$ruleGrpName" "$ruleName" "$description" "$refNumber" "$isCommentedOut" "$notes" \"\" NAMED_OBJECT=servobjconditionObject

          blcli_storeenv TEMPLATE

          echo "\\n"

           

          }

           

          ## TO BE USED TO TEST THE CONDITION IF REQUIRED##

          function addpropertycond {

          echo "Adding Property Condition Rule"

          echo "\\n"

          blcli_execute Template addRuleWithCondition NAMED_OBJECT=template "$ruleGrpName" "$ruleName" "$description" "$refNumber" "$isCommentedOut" "$notes" \"\" NAMED_OBJECT=propconditionObject

          blcli_storeenv TEMPLATE

          echo "\\n"

           

          }

           

          lookuptemplate

          buildpropertycond

          buildserverobjcond

          buildifcond

           

          ## TO BE USED TO TEST THE CONDITION IF REQUIRED##

          #addserverobjcond

          #addpropertycond

          • 2. Re: Unable to create an If, Then condition for a Template Rule
            Dan Chan

            Hi Peter,

             

            Were you ever able to get this to work?