Creat and Edit a record with some default information from another table

Creat and Edit a record with some default information from another table

  

Hi,

I need some help for this isse.


- Scenario:

I introduced 4 students in the system USERS entity and then introduced the "Classification" in the USEREXTINFO entity.

When, for example, student 1 logs in into the application, it will have to enter the data, in "Students" web page, but the "classification" field must already be filled by default according to the information in the user extension table and after saving the whole information, it should be included in the "STUDENTS" entity.


- Database diagram:


USEREXTINFO

----------------

Id

UserId

ClassId



CLASSIFICATION

----------------

Id

Class (Values - A/B/C/D)



STUDENTS

----------------

Id

UserId

ClassId (Combobox from USEREXTINFO table)

YearId  (Combobox from TEACHINGYEAR table)

Address

Phone

Email



TEACHINGYEAR

----------------

Id

Year (Values - 10º/11º/12º)



- The issue is:

How can I put the "Classification" field with the value that exists in the USEREXTINFO entity for Student 1?


Thanks in advance,

Clara


Hi,


This is my database diagram:

To test you will have to choose 4 UserId that exist in your Users system entity and in the UserExtInfo entity you have to replace with your 4 UserIds. In my case I use my User's Id 216, 217, 218 and 219.

By Excel, I entered the data In the Student entity but only for the "UserId 216".


I log in with the "UserId 219" and I go to the Students menu and I see the list with the student data "UserId 216" and I see the detail and everything is fine.
When I go to "Create a new student", I check that my "UserId=219" is correct but the remaining values are incorrect.


What I expected:
- User field = User.Name
- Classification field = UserExtInfo.ClassificationId
- Email field = User.Email


If anyone can help me, I appreciate it.

Regards,

Clara





Clara,

The variables in the input fields of the form are not correct. All of them should come from: StudentForm.Record.Students

E.g. The variable of the user field should be:  StudentForm.Record.Students.UserId


Regards,

José



Hi José Costa,

Thanks for your answer.


I made the changes as you said but the results are still not as expected.


Log In with my UserId = 218


When I "Create a new Student" I have these results:


What I'm doing wrong?


Regards,

Clara


Clara,

Your aggregate which is the source for your form is not right. If you want a specific Student record given by the input parameter, then you have to filter the aggregate to give you the Student record whose Id is the same as the input parameter:

Also, for that form you do not need the entities User and UserExtInfo in the aggregate:

Tell me if that solved your issue.

Also, I do not know exactly what you are trying to do, but I guess you should review your data model. For example, if the relation of the entities User and UserExtInfo is a one-to-one relation then you should change the type of the Id of the UserExtInfo entity to be of User Identifier.

Cheers,

José

Thank you for getting me logged in.

And for a good forum. I'm happy to share the work, experience, fun to entertain. And a useful knowledge. For the collective.


Hi José Costa,

Thanks for your answer and your solution but unfortunately it did not solved my issue.

I expected "User" field already with the Name (User.Name) filled in, "Classification" field with the Classification (UserExtInfo.ClassificationId) and the "Email" field with the email address (User.Email).



Regarding my data model,  the relation of the entities User and UserExtInfo is a one-to-one.

If I understand, you sugest change the Data Type for "Id" field from UserExtInfo entity, correct?


but when I do that and try to publish I have an "Database Upgrade Error"



Regards,

Clara


Clara,

My mistake...

What you want is to get the Student information from the user that is logged on. Right? Assuming that you only have at most one record of Student for each record of User (ono-to-one relation), do this in the filter:

Let me know if that solves it.

Regarding the second issue, if in the database you do not have any meaningful data, you can do this:

  1. Copy and paste entity  UserExtInfo (you will get a new UserExtInfo2)
  2. Change the attributes of UserExtInfo2 accordingly
  3. Delete entity UserExtInfo
  4. Rename UserExtInfo2 to UserExtInfo

This will delete all data in entity UserExtInfo and will bind all previous references to the old UserExtInfo in your application to the new entity. Don't mind the errors until after step 4. Then you have to deal with the remaining errors.

See if it helps.

Cheers,

José


Hi José Costa,

Thanks again, but unfortunately it did not solved my issue.

Yes, when I create a "New Student" I want to get information from the student/user that is logged and that is in the User and UserExtInfo entity.


Logged in with UserId 219.

Students List Page - Only have this record on my Students entity



Students Detail Page - UserId 216 registration details


When I "Create a new Student" I have these results:


Regards,

Clara

Thank you for getting me logged in.

Clara,

Let me ask you something:

- After the changes that I suggested for you to do in the aggregate and form, when you create a new user, does it show in the Students list?

- If yes, when you click on that student in the Student list, does the correct information show up in the StudentDetail?

Cheers,

José


Hi José,

Sorry for my answer delayed.

1 - If I create a new user and force the correct values for my user Logged, it show in the Students list.

2 - I only have two records in the list (UserId 216 and UserId 218) and both records, in details students page, give me the same information, in that case, the data related with user is logged in (UserId218). If I log off and log in with UserId 216, both records give me the details from UserId 216.


Regards,

Clara



Solution

Hi Clara,

See the attachment for a possible solution.

I changed the aggregate as in the previous solution to get the Student record. And added logic such that, if the StudentId is NullIdentifier, then it fills the record from the aggregate with the remaining atributes (UserId, ClassificationId and Email).

See if that woks.

Cheers,

José

Solution

Hi José,

Thanks for you solution.

Regards,

Clara