18
Views
7
Comments
Solved
Adding multiple entries at the same time

I want to add multiple elements to a table at once. I have 3 tables: users, categories, and usersCategoriesRel. Users and categories tables have a many-to-many relationship and they are related together using usersCategoriesRel table. Now, I am trying to create an admin panel to allow the admin to add multiple categories to a certain user. What I was able to do is adding a single entry at once: add a userId and a categoryId to usersCategoriesRel table. What I want to achieve is having a list of checkboxes. Each checkbox will represent a certain category and if it is checked, it will be added to the database. Otherwise, it will not.


I have created the checklist and it views the categories correctly. However, I have two problems:

1. I do not know what value should the checkboxes values be set to. Logically, each checkbox should be equal to True if there is an entry inside the usersCategoriesRel table with the current user's id and the selected category id. Otherwise, it should be set to False.

2. After solving the first problem, I do not know how to add all the checked elements into the table. I am used to adding a single entry at once.

ChemSchool.oml

mvp_badge
MVP
Rank: #75
Solution

Hi Omar,

Sorry! my mistake :)

As per the requirement, I have changed the implementation approach in the attached updated .oml file. Please check the same.

Note: Instead of mapping the TableRecords widget's Source Record List property with the result-set of the GetCategories aggregate defined in the preparation flow, I have defined & referred to a local variable of STR_Category List data type. 

Let me know if you do have any confusion in understanding the implemented flow.

Hope this helps you!


Kind regards,

Benjith Sam

ChemSchool.oml

Rank: #56380

Thank you so much! It worked.

mvp_badge
MVP
Rank: #75

You're most welcome, Omar 

Glad to help you :)


Kind regards,

Benjith Sam

mvp_badge
MVP
Rank: #75
Solution

Hi Omar,

For the mentioned use-case, I have created a screen called AdminScreen (incorporate the required changes as per your need) for demonstrating the functionality which you are trying to achieve. Please refer to the attached updated .oml file.

Points to notice

  • I have introduced an additional ad-hoc Boolean data type attribute called isSelected (which is mapped with the checkbox widget's variable property, inside the TableRecords widget - first column), in the GetCategories Aggregate defined in the Preparation action flow, in order to track the Category checkbox selection.
  • For better understanding, I have also mentioned some comments against the logic defined within the AddUserCategories button action flow.


Hope this helps you!


Kind regards,

Benjith Sam  

ChemSchool.oml

Rank: #56380

Thank you so much! 

The second point was resolved. However, I still do not know how to set the default values the check boxes as I mentioned.


mvp_badge
MVP
Rank: #75

You're welcome, Omar :)

Based on my understanding of the mentioned 1st point, I have defined a logic flow for the User Dropdown OnChange handler. please check the updated attached .oml file


Hope this helps you!


Kind regards,

Benjith Sam

ChemSchool.oml

Rank: #56380

I have developed a similar approach (almost the same code) but none of them worked. I have debugged and I can see that the conditions are met and the assign operation happens properly. However, after the loop ends, I check the values of IsSelected property for the categories aggregate and they are all set to False. I do not know whether this may be related to setting the default value for them to False or not.

I have also added an Ajax Refresh for both the CategoryTable and Users_ComboBox but no differenence!

mvp_badge
MVP
Rank: #75
Solution

Hi Omar,

Sorry! my mistake :)

As per the requirement, I have changed the implementation approach in the attached updated .oml file. Please check the same.

Note: Instead of mapping the TableRecords widget's Source Record List property with the result-set of the GetCategories aggregate defined in the preparation flow, I have defined & referred to a local variable of STR_Category List data type. 

Let me know if you do have any confusion in understanding the implemented flow.

Hope this helps you!


Kind regards,

Benjith Sam

ChemSchool.oml

Rank: #56380

Thank you so much! It worked.

mvp_badge
MVP
Rank: #75

You're most welcome, Omar 

Glad to help you :)


Kind regards,

Benjith Sam