I have a rule:
If Account IS NEW Then
Account.AccountNumber=COUNT Account
But when Icreate a new Account on the new form its AccountNumber is blank. Its correctly set after the Create button is clicked though.
I have a workaround using UNDEFINED. But thought that this behaviour should be different.
Terry
IS NEW is not an initialization rule
-
- Posts: 7532
- Joined: Sun Apr 24, 2005 12:36 am
- Contact:
-
- Posts: 595
- Joined: Sun Apr 24, 2005 2:22 am
- Contact:
There is a good reason for this behaviour. The system executes rules with condition IS NEW when the object is actually created and saved in the database. Making assignment 'Account.AccountNumber = COUNT Account' at that very moment means that the account number will be unique.
Contrary to this, the system considers rules with condition IS UNDEFINED as initialization rules and executes them before the form for the new object is displayed to the user so that the initial values are shown on the form. If two users start registering a new account at the same time (i.e. within a short interval of each other), they will both see a form for their new account with the account number initialized to the same number. When the users finish entering data and submit their accounts for creation, the system will not re-assign the account number because it is no longer undefined - it is submitted with the other data entered by the user. As a result, both of the new accounts will end up having the same account number.
The same logic applies if you want to automatically set a Timestamp attribute to CURRENT_TIMESTAMP. If you use the condition IS NEW, the time will be set when the object is actually created in the system. If you use the condition IS UNDEFINED, the time will be set when the form is displayed to the user for data entering. Unless the user clears the automatically initialized value, it will be used when the object is created and saved in the database (i.e. some time later).
Contrary to this, the system considers rules with condition IS UNDEFINED as initialization rules and executes them before the form for the new object is displayed to the user so that the initial values are shown on the form. If two users start registering a new account at the same time (i.e. within a short interval of each other), they will both see a form for their new account with the account number initialized to the same number. When the users finish entering data and submit their accounts for creation, the system will not re-assign the account number because it is no longer undefined - it is submitted with the other data entered by the user. As a result, both of the new accounts will end up having the same account number.
The same logic applies if you want to automatically set a Timestamp attribute to CURRENT_TIMESTAMP. If you use the condition IS NEW, the time will be set when the object is actually created in the system. If you use the condition IS UNDEFINED, the time will be set when the form is displayed to the user for data entering. Unless the user clears the automatically initialized value, it will be used when the object is created and saved in the database (i.e. some time later).
Aware IM Support Team
-
- Posts: 595
- Joined: Sun Apr 24, 2005 2:22 am
- Contact:
It is also important to note that condition IS NEW becomes TRUE only after the object instance is saved in the database. Therefore, in the rule
If Account IS NEW Then
Account.AccountNumber = COUNT Account
the COUNT will include the newly created instance, whereas in the following initialization rule
If Account.AccountNumber IS UNDEFINED Then
Account.AccountNumber = COUNT Account
which is executed before the instance is created, the COUNT value will be one less.
You may also consider a different approach to numbering:
If Account IS NEW Then
Account.AccountNumber = MAX Account.AccountNumber + 1
This approach guarantees that the new account number will be unique. It will be one more than the largest existing account number. With the 'COUNT Account' approach it is possible that more than one account is assigned the same number if the users are allowed to delete accounts from the system.
If Account IS NEW Then
Account.AccountNumber = COUNT Account
the COUNT will include the newly created instance, whereas in the following initialization rule
If Account.AccountNumber IS UNDEFINED Then
Account.AccountNumber = COUNT Account
which is executed before the instance is created, the COUNT value will be one less.
You may also consider a different approach to numbering:
If Account IS NEW Then
Account.AccountNumber = MAX Account.AccountNumber + 1
This approach guarantees that the new account number will be unique. It will be one more than the largest existing account number. With the 'COUNT Account' approach it is possible that more than one account is assigned the same number if the users are allowed to delete accounts from the system.
Aware IM Support Team