Hidden Concepts of ATG Repository- Part 2

2. Required , Unique and Default Properties

Scenario 1: You have property of Item, that is must required for creating Item.From DataBase perspective, you have column which cannot be null and requires user entered value.

Solution 1: Use the attribute required=true at property level.

           <property name="mustNeeded" data-type="string" required="true" />

Dont's:
  • If DataBase defines NOT NULL constraint to column, then required attribute must be set to "true". Vice-versa is not always true, if you are not manually entering the data in DataBase.In other words, even if the NOT NULL constraint is not defined, it would still go good.
  • If Property reference to other Item, you can only set required="true" at repository level, but donot add constraint NOT NULL to column in DataBase.(Reason: During Deployments, BCC writes row without reference properties first and then Updates the same row with properties with referenced properties.)
  • Donot add required attribute to collection properties. like, data-type="set". Its not supported by ATG.


Scenario 2: You have property of Item, that needs to unique. From the DataBase Perspective, you have column that is unique and that's not Primary Key of table too. 

Solution 2: Use the attribute unique and set the value to true.


              <property name="login" data-type="string" required="true">
                   <attribute name="unique" value="true"/>
              </property>

Dont's:
  • If DataBase defines UNIQUE constraint to column, then unique attribute must be set to "true". Vice-versa is not always true, if you are not manually entering the data in DataBase.In other words, even if the UNIQUE constraint is not defined, it would still go good.


Scenario 3: You have property of Item, that needs to have default value, if user hasn't entered any value. From the DataBase Perspective, you have column that has default value.

Solution 3: Use the attribute default and provide the value for it.
                    <property name="favoriteColor" data-type="string" default="blue"/>              

2 comments:

  1. ATG BCC has a funky behavior and here is how it will happen...

    "Even with required="true" and NOT NULL defined in the column definition, the BCC will ignore the required condition if and only if the required property exists under a different tab"

    For example, under General tab for a category asset, the 'name' and 'id' are required. If you introduce another required property under a different tab, say Advanced tab then BCC will let you create the asset as long as Advanced tab was never clicked during the creation of the new asset.

    Please try and confirm if that is the case on your end too. I am sort of tired staring at the required="true" flag and NOT NULL definition in the DB :(

    - fs

    ReplyDelete
    Replies
    1. No. It works properly.

      Even if required property is under different tab other than "General", it will pop up errors on screen.

      Which version of ATG are you working?

      Rgds,
      Iranna

      Delete