Auto filling user & date in form

Hi, I am creating a traditional web application that would have a form in it that would auto-populate the form with the date that the form was created as well as the user that created it.  I would like the form to be populated with this information as the form is being open. to do this could I add logic to the preparation so that this information is in the form when the user creates it? if so how would I go about that?

Jay Brooks wrote:

Hi, I am creating a traditional web application that would have a form in it that would auto-populate the form with the date that the form was created as well as the user that created it.  I would like the form to be populated with this information as the form is being open. to do this could I add logic to the preparation so that this information is in the form when the user creates it? if so how would I go about that?

Hi Jay, when you are creating a new record to do that you can use the GetUserId() to get the user id to save on the form and GetUser(GetUserId()).User.Name to present the name on the screen from the user logged in and CurrDate() or CurrDateTime() but if it is an edit you must take this from the preparation


Best regards

Carlos Lessa


Check these pics, is how you would present on the screen

Cheers

Hi Jay,

In order to visualize Carlos' answer, see a screenshot below. 

So the idea is to add a SubmittedBy (type UserIdentifier) and SubmittedDate (type Date/Date Time) entity attributes to the entity you want to display in your form. Best practice is to then create a wrapper action (like Movie_Create) around your entity. Inside that wrapper action before executing the default Create action, you can assign the values GetUserId() and CurrDate() or CurrDateTime() to your Entity record. Now each time you create a record, use the wrapper action so that the fields SubmittedBy and SubmittedDate will automatically be filled.

The result is, when you open a detail screen with your Form to display an entity record, the fields SubmittedDate and SubmittedBy will be already filled.

Hope this helps!

Regards,

Nordin

EDIT: I now see I have misread your requirement, you should go with Carlos' initial answer. My explanation is still a good practice if you have not done so already :)

Carlos Lessa wrote:

Check these pics, is how you would present on the screen

Cheers

Hi Carlos, would this solution just show whatever user was opening up the form in the detail screen as the person that submitted the form? this form would be created by one person but then could be viewed by another person and i am trying to have the submitted by stay static. can that be done with an expression?

i uploaded an OML where i tried to use an expression the way that you mentioned but when i switch to a different user it just says that the new user is the one that submitted the form

Jay Brooks wrote:


Hi Carlos, would this solution just show whatever user was opening up the form in the detail screen as the person that submitted the form? this form would be created by one person but then could be viewed by another person and i am trying to have the submitted by stay static. can that be done with an expression?

i uploaded an OML where i tried to use an expression the way that you mentioned but when i switch to a different user it just says that the new user is the one that submitted the form

Hi Jay this solution compares if in the aggregate the submittedBy is empty or not, if not empty it will populate with the name from the id saved in the db, if empty getts the id of the logged user.

In your case is getting always the name of the logged user because you don't have users assigned to your project its all empty, checking the pic bellow, you do a bootstrap for your project but you don't assign a user to submitedby or date to submitteddate

when I put a filter on your aggregate to filter by SubmitedBy <> NullIdentifier it shows that you dont have any user assigned in your table

when I do the same and I put submitedby = Nullidentifier returns all records and the user is null

Solution
Processing Upload...

I changed the Name expression to be correct, instead of looking for empty submitedby is looking by projectid = nullidentifier, what says, if projectid = null, means is a new reord and I'm getting the logged user, if different of null isnt new project and I'm getting the user in the submitedby from the DB, and if project id is not null and subimitedby is null return " not found"(cuz if not your app gives an error cuz your are trying to bring the name of a null value user)

Also changed the Date to do the same logic and expression cuz you dont need to change the dates

The changes are in the oml attached, you just need to make the logic to assign the users and dates on the bootstrap and you see in the pic

hope I could help you

Best regards

Carlos Lessa

Solution

looks the oml didn't upload, lets try again

Carlos Lessa wrote:

looks the oml didn't upload, lets try again

Thanks for all this Carlos, I really appreciate it.


Jay Brooks wrote:

Carlos Lessa wrote:

looks the oml didn't upload, lets try again

Thanks for all this Carlos, I really appreciate it.


no worry, after tell us if you solved the problem