Updating an attribute with logged in user and timestamp

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
ACDC
Posts: 1148
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Updating an attribute with logged in user and timestamp

Post by ACDC »

Hi

I am new to AwareIm and this forum, please can someone assist me with this as I am going around in circles

I have the following attributes in each one of my objects. I would like to get the system to update these automatically at the time of adding and editing the object.

1. CreatedBy: (Unable to get this working by assigning it as a SystemUser - tried all the options but get "NONE" on the form)

2.DateCreated: ( This one was easy as I found the example in the Library Example - by assigning it as a timestamp with initial value set to CURRENT_TIMESTAMP )

3.DateTimeModified: (Every time the object is edited, this attribute needs to be updated with the current date timestamp at time of edit)

4.ModifiedBy: (Every time the attribute is edited then the logged in user must be inserted automatically by the system)

Thank you in advance
aware_support
Posts: 7526
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Post by aware_support »

You need to add the following rules to your objects:

1.
IF MyObject IS NEW Then
MyObject.CreatedBy = LoggedInRegularUser

(the attribute CreatedBy must be a reference to a RegularUser object)

3.
IF Not MyObject IS NEW Then
MyObject.DateTimeModified = CURRENT_TIMESTAMP

4.
IF Not MyObject IS NEW Then
MyObject.ModifiedBy = LoggedInRegularUser

(the attribute ModifiedBy must be a reference to a RegularUser object)
Aware IM Support Team
ACDC
Posts: 1148
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Post by ACDC »

As a beginner, that was good lesson in basic rules and automating data input

Theres nothing better than learning on the fly, and getting great feedback like this. I would have taken hours to work that one out and now its embedded in my brain.

There is just one thing though, on the 'Created By" and "Modified by" ,because they are referencing another object they are not ready only. Is there a way of disabling the drop down so its read only. The calculated field seems to be ignored for these two attributes, and the only way I can force this into a read only, is by displaying the attribute as a table list (show 1 item only) and deleting the edit and delete option. This does not seem to be the ideal way of doing it - Any suggestions

Thank You
aware_support
Posts: 7526
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Post by aware_support »

"Calculated" should not be ignored (if it is it must be a bug - are you sure it is?). The other approach is use access levels or PROTECT rule to limit or completely disallow access to these attributes for different users.
Aware IM Support Team
ACDC
Posts: 1148
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Post by ACDC »

I double checked this again, and I think it is a bug. The reference attribute ModifiedBy and CreatedBy in the RegularUser object, although calculated is checked, is not displaying on the form as Read Only. So maybe you can check this out and if so, submit it as a bug to be fixed.

In the meantime I will attempt to use PROTECT, but my concern here is, the attribute ModifiedBy changes all the time by a rule, will PROTECT allow this to happen ? (just want to make sure about this before tinkering with PROTECT)

Thank You
ACDC
Posts: 1148
Joined: Sat Jun 30, 2007 5:03 pm
Location: California, USA

Post by ACDC »

After experimenting with Protect and according to the Help, you are not allowed to protect attributes of a referenced object.

So, how do you make an attribute referenced to an object read only ? :?:
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

ACDC,
Going back to the original issue. I don't think this is a bug, but instead you need to add some additional shortcut fields to accomplish your end result.

Using the BO name from Support's rules example above, create 2 more shortcut fields in MyObject BO:
- CreatedByLoginName: shortcut to CreatedBy.LoginName
- ModifiedByLoginName: ModifiedBy.LoginName

On your form for MyObject, delete the reference fields
- CreatedBy
- ModifiedBy

On your form for MyObject, add the reference fields
- CreatedByName
- ModifiedByName

You should now find that the login name of the user shows up in approproate read only fields on you your form.

If you don't want to do this with shortcuts, the CreatedBy and ModifiedBy fields could have been set up as text / read only fields. The result would be the same.

If you would like me to send you the sample bsv I created to test this, PM me with your email address.

Tom
Post Reply