Good morning Arao.
If your activities list is static the best way is using a check box for each one, in the other hand if your activities list is dynamic (you have it in a table that the users manages), something like users and groups the users belongs to, you should do it this way:
This is what you will get:
- Result
- Pic1.jpg (45.03 KiB) Viewed 5009 times
1) In my case I have created a valueList with the Groups table, returning the groupID. Also a relation between the table Users and UsersGroups on the userID.
UsersGroups holds the groups a user belongs to.
2) The form has a form variable "usersGroups" type String:
- Code: Select all
/**
* @type String
*
* @properties={typeid:35,uuid:"B09E7518-D379-4082-BFE8-C7EFBB9D5585",variableType:12}
*/
var userGroups = '';
3) I have placed a check field on the form with this properties:
3.1) displayType: CHECK
3.2) dataProvider: userGroups
3.3) valueList: vlGroups
4) The onRecordSelection event of the form has the following code: What it does is load the groups for that user as an array in the userGroups form variable.
This code is not inside the event, is a separated function but I call it from the onRecordSelecion event.
- Code: Select all
if (utils.hasRecords(foundset.users_to_usersgroups)) {
userGroups = databaseManager.convertToDataSet(foundset.users_to_usersgroups, ['groupid']).getColumnAsArray(1).join('\n');
}else{
usersGroups='';
}
5) The onDataChange event of the field usersGroups has the following code:
- Code: Select all
function usersGroups_onDataChange(oldIDs, newIDs, event) {
if(!frmIsAdding){
var fs = users_to_usersgroups.duplicateFoundSet();
var idColumnName = 'groupid';
var nombreColumnName = 'groupname';
var id;
oldIDs = (oldIDs) ? new String(oldIDs).split('\n') : [];
oldIDs.sort();
newIDs = (newIDs) ? new String(newIDs).split('\n') : [];
newIDs.sort();
if (newIDs.length > oldIDs.length) {
id = newIDs[newIDs.length - 1];
for (i in oldIDs) {
if (oldIDs[i] != newIDs[i])
id = newIDs[i];
}
if (fs.newRecord()) {
fs[idColumnName] = id;
databaseManager.saveData(fs.getSelectedRecord());
// Here some code to add the user in the group in the Servoy Security
}
}else {
id = oldIDs[oldIDs.length - 1];
for (i in newIDs) {
if (oldIDs[i] != newIDs[i])
id = oldIDs[i];
}
if (fs.find()) {
fs[idColumnName] = id;
if (fs.search()){
// Here some code to delete the user from that group in the Servoy Security
fs.deleteRecord();
}
}
}
updateUI(); // This will call the function I showed in step 4
return true;
}else{
return true;
}
}
I took this code from the Servoy samples and adapted it to my needs.
I hope this can help you