How to set the defaultSelectedItems value of Multi Person combo box in Powerapps? - powerapps-formula

I would like to set the DefaultSelectedItems value with multiple person selection from a previous Gallery.
Since I'm managing multiple people, I need to create a table with the selection but since I don't know the number of records selected by the user, I cannot create it.
For example, this is the code if the user selects 2 people:
*
Table(
{
'#odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: First(Gallery1.Selected.'Crew').Claims,
Value: First(Gallery1.Selected.'Crew').DisplayName
},
{
'#odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims: Last(Gallery1.Selected.'Crew').Claims,
Value: Last(Gallery1.Selected.'Crew').DisplayName
}
)
*
How can I generalize it?
Thanks!

Kindly try the formula below
ForAll(Gallery1.AllItems, Crew)
Let me know if it works or not

Related

Label gets selected on clicking enter key in the tabulator cell

I have a js fiddle to show the issue that I am facing.
Tabulator 'email' column has freetext set to true to allow the user to set the value of the cell to a free text entry as follows:
editorParams:{
values:{
"steve#boberson.com":"steve",
"bob#jimmerson.com":"bob",
"jim#stevenson.com":"jim",
"harvy#david.com":"Harvy",
"ken#thompson.com":"Ken",
"denny#beckham.com":"Denny"
},
freetext:true,
searchFunc:function(term, values){
console.log("term and val "+term +" \n"+values);
var matchedEntries = {};
var matchFound = false;
for(var key in values) {
if(key.includes(term)){
matchFound = true;
matchedEntries[key] = values[key];
}
}
if(matchFound){
return matchedEntries;
}
else{
return {term: term};
}
}
}}
Select one of the values from the selector list displayed, say steve, value being 'steve#bobberson.com'.
Then after the value is selected, click on the same tabulator cell, the value displayed suddenly changes to the label.When user clicks enter key now, the label is selected instead of the value,.ie. steve will be displayed instead of steve#bobberson.com
If this is not a bug, how do I make sure that the value steve#bobberson.com remains selected after clicking enter. This is because freetext option is set to true in the editorParams of the column
Attached a gif showing the issue
That is not a bug,
With freetext enabled, users are able to enter any text they like in that field and it will be saved which is exactly what is happening in the example
If they select the email address again from the list then it is correctly saved.
It is an either/or scenario, you can either restrict the users to selecting specific values from the list OR you can allow them freetext in which case anything goes.
If you want a different behaviour then you can always build a custom editor that works in the way you want. Checkout the Custom Editor Documentation for more information

Whats the best way to handle related data ids using Tabulator

Using Tabulator, if you have a 'select' editor and want it to link to values 'Male' and 'Female' but underneath male and female are values from another physical database table with id values of 1 and 2 (which are different than the 'row' id), whats the best way to do something like this?
The 'select' editor has ways to specify the display of items in the drop down and a literal display of the selected value, but no place for a hidden (not displayed) underlying ID of the selected value to pass when saving the data.
We could wrap the select data values in divs with a data attribute for the selects values ids and then pass that when updating, but are not sure this is the best option considering how Tabulator works. We could also just pass the raw selected value and then look it up on the server to get the associated ID, but that seems like a lot of overhead and tightly couples the server to the client, which wouldn't work for something like a 3rd party API where we have no server control.
Any thoughts on how best to handle something like this are appreciated!
The select editor allows for values to be passed in a number of ways, including specifying both the items value and its user visible label
If you want to show a different lable to the value you want to store, you can pass in an object, where the key of each property is the value that will be stored if it is selected, and the value of each property will be the lable displayed for it in the list.
{title:"Name", field:"name", editor:"select", editorParams:{
values:{
"steve":"Steve Boberson",
"bob":"Bob Jimmerson",
"jim":"Jim Stevenson",
}
}}
For more complex option lists you can use an array of objects, that allows you to define option groups, and disabled options.
{title:"Name", field:"name", editor:"select", editorParams:{
values:[
{ //option group
label:"Men",
options:[ //options in option group
{
label:"Steve Boberson",
value:"steve",
},
{
label:"Bob Jimmerson",
value:"bob",
},
]
},
{ //option group
label:"Women",
options:[ //options in option group
{
label:"Jenny Jillerson",
value:"jenny",
},
{
label:"Jill Betterson",
value:"jill",
},
]
},
{//ungrouped option
label:"Other",
value:"other",
},
]
}}
For full details on how to use this editor, checkout the Editor Documentation
Finally figured this out. You need to use the lookup formatter to display the text value using the same params as the select editor. This is not obvious since none of the select editor examples in the docs show use of it. Anyway, here is a simple example showing it in both directions. Of course you would want to abstract the data out instead of literally duplicating it, but here to help show the literal use, it is duplicated:
{
title:"Example",
field:"example",
editor: "select",
editorParams:{
"1": "Cute",
"2": "Fine",
"3": "Scary",
},
formatter:"lookup", // display option, but store value
formatterParams:{
"1": "Cute",
"2": "Fine",
"3": "Scary",
}
}

Kentico Admin - Dynamically Change and SAVE Field Name, Value and Label

For a custom page type, I have a multiple choice form filed as seen in image 1 and 2. I was able to set it up (using jquery) so that when I click on other checkboxes belonging to a another field, the checkbox Label and value of this field is changed accordingly as seen in image 3 - 'Author1', 'Author2', 'Author3' were replaced with something else.
The problem is when I hit the Save button, all of my new label/value are not Saved, but the checkbox value and label return to its original value.
Is there a way to make it so that these checkboxes can accept new value and the new value can be saved. Thanks!
Where does authors values come from? Database? You should be able to use SQL query as data source for multiple choice control. This will allow you to store actual values into database whenever you save a page on the Form tab.
So the idea is to load actual values, replace them with 'AuthorN' and change back to original value when checked.
I've set up an example which might help you. I've created a form with three fields:
FirstAuthor
Type: Integer
Form control: Radio buttons
Data source: SQL Query (select userid,username from cms_user)
Has depending fields: true
SecondAuthor
Type: Integer
Form control: Radio buttons
Data source: SQL Query (select userid,username from cms_user)
Has depending fields: true
OrderedAuthors
Type: Text (1000)
Form control: Label
Default value: {% (if(firstauthor>0) { GlobalObjects.Users.Where("userid="+firstauthor)[0].UserName } else {""}) + ", " + (if(secondauthor>0) {GlobalObjects.Users.Where("userid="+secondauthor)[0].UserName} else {""} #%}
Depends on another field: true
I guess you have a list of authors somewhere in the database so you can just replace CMS_User table with your table. Then all you need to do is to adjust the macro in the third field to give you results you want.

How do you determine which row was selected in a Infragistics WebHierarchicalDataGrid when you have a Master Detail table configuration

I have a master table and two child detail tables under the master. When the user selects one of the detail tables the RowSelection event fires. I need to determine which table was selected. If the users selectes the second detail table then I need to obtain the data from a specific field. What code can be put in place to make this determination. Here is the code I have so far to grab the data, I just need to build the IF statment around this code.
String UploadIndex;
if (e.CurrentSelectedRows.Count > 0)
{
GridRecord oRow = e.CurrentSelectedRows[0];
UploadIndex = oRow.Items[0].Value.ToString();
}
Tried this but got controlmain is inaccessible due to its protection level.
ContainerGrid oRowIsland = WebHierarchicalDataGrid1.GridView.Rows[e.CurrentSelectedRows[0].Index].RowIslands[0];
if (oRow.Owner.ControlMain.ID == '2')
{
UploadIndex = oRow.Items[0].Value.ToString();
}
Use ContainerGridRecord type instead of GridRecord when declaring oRow, this way you will have access to oRow.Owner.ControlMain which is the grid that holds the row. In debug determine ID of the grid you're interested in and then you can do
If (oRow.Owner.ControlMain.ID == '...ID of second grid') {
// profit
}
Or use some other easily identifiable property of ControlMain grid that in your case assocciate with the second details.

grocery crud add button to copy row in another table

I have 2 tables: customers and standby and I added a new button into my grocery crud in standby in that way:
$crud->add_action('Send', '', 'standby/copyrow','ui-icon-plus');
Both tables have the same fields, in standby I receive data from a form and the idea it's when I click "Send" copy that id ino customers and delete that id from standby
In other words I need to add a row from the first table (where I added a new button) into the second one, and then delete that row from the first table.
then I created a function
function copyrow($id)
{
// I don't know how can I add that row
}
Hope someone can help me, thanks in advance!
Tables that i used in this code:
First table name - customers
and Fields - a(primary key,auto increment), b
Second table name - standby
and Fields - c(primary key,auto increment), d
Make changes to your code that you want..
function copyrow($id)
{
$customers=$this->db->select('b')->where('a',$id)->get('customers')->result();
foreach ($customers as $customer)
{
$this->db->set('d', $customer->b);
$this->db->insert('standby');
$this->db->delete('customers', array('a' => $id));
}
}
I sure that you will help this code.

Resources