I created a form with a single data source: InventJournalTable.
I also added a grid on it and two field from the data source : JournalType and JournalId
The ActionPane has a button and in its clicked event handler I am trying to do the following:
1. add a new data source and join it with the current one on JournalId
2. add to fields from the newly added data source to the current Grid.
This is what I have until now ... just for testing.. I have tried to access data source and add a range. It works nice, maybe the join is working too, but how can I add those two fields?
void clicked()
{
Query query;
QueryBuildDataSource qbdsInventJournalTable;
QueryBuildDataSource qbdsvwInventJournals;
super();
query = InventJournalTable_ds.query();
qbdsInventJournalTable = query.dataSourceTable(tableNum(InventJournalTable));
qbdsInventJournalTable.addRange(fieldNum(InventJournalTable, JournalType)).value(queryValue(InventJournalType::LossProfit));
qbdsvwInventJournals = qbdsInventJournalTable.addDataSource(tableNum(vwInventAdjJrnlCostAmount));
qbdsvwInventJournals.addLink(fieldNum(InventJournalTable, JournalId), fieldNum(vwInventAdjJrnlCostAmount, JournalId));
qbdsvwInventJournals.joinMode(JoinMode::OuterJoin);
//gridOverview.addDataField(
InventJournalTable_ds.executeQuery();
}
One more thing, I plan to add another button named "Remove details" which will remove the second data source and the grid should return to its initial state.
Am I on the right track at least? Can I get some hints about this?
Instead of dynamically adding the datasource/fields/etc have you considered just adding them on the form, but disabling the joined datasource until you need it? Seems to me like a simpler/cleaner solution.
See here:
http://olondono.blogspot.com/2008/06/how-to-enable-or-disable-joined.html
Related
Hypothetical:
Say i'm having someone order a cake and they choose vanilla or chocolate, and then they have to choose a frosting
if vanilla: strawberry or buttercream
if chocolate: mocha, dark chocolate or buttercream.
Right now the frosting value in the data model can accept all four options, so all four show up in the dropdown.
a) is there a way to change the binding for the second dropdown after the first is chosen?
This can be done without having the data saved in any datasource. Simply do the following...
Suppose the first dropdown is named primaryDropdown and the second dropdown is called secondaryDropdown. In the primaryDropdown options set the following:
["Vanilla", "Chocolate"]
Also, make sure to uncheck the option allowNull and on the onAttach event handler, place the following:
widget.value = "Vanilla";
Now we move on to the secondaryDropdown. Here, we will do a binding so place the following in the options value:
getAvailableOpts(#widget.root.descendants.primaryDropdown.value)
In the client script, we need to make sure that function exists so please paste the following in any client script:
function getAvailableOpts(primaryValue){
var options;
switch(primaryValue){
case "Vanilla":
options =["Strawberry","Buttercream"];
break;
case "Chocolate":
options = ["Mocha","Dark Chocolate","Buttercream"];
break;
default:
options = [];
}
return options;
}
From here, you are good; However we can still make it better. For that, make sure to also uncheck the allowNull option for the secondaryDropdown and then we need to add some logic in the onValueChange event handler of the primaryDropdown.
widget.root.descendants.secondaryDropdown.value = widget.root.descendants.secondaryDropdown.options[0];
References:
https://developers.google.com/appmaker/ui/input-widgets#dropdown
https://developers.google.com/appmaker/ui/binding#bindings
https://developers.google.com/appmaker/scripting/client#use_scripts_in_binding_expressions
Im guessing you set the dropdown "possible value" options in the data source and you have those fields as just string fields in your table.
the quick and dirty way to do this is go to the Cake drop down and on the Property Editor>Events>OnValueChange select Custom Action and use this Code
if(widget.value==="Vanilla"){
widget.root.descendants.Field.options = ['Strawberry','Buttercream'];
}else if (widget.value === "Chocolate"){
widget.root.descendants.Field.options = ['Mocha','Dark Chocolate','Buttercream'];
}
"Field" here is replaced with the name of the dropdown box for your frostings
also go to the property editor of the frostings dropdown and delete everything in the options field there.
I was trying to solve for a similar situation and created an additional table to serve as a lookup.
I have a drop down for CATEGORY with possible options set on the field in the main data source.
Then I have a second table with 2 Columns: CATEGORY, and SUB_CATEGORY.
On the entry form I have options for the SUB_CATEGORY drop down set to SUB_CATEGORY on the CATEGORY_MATRIX lookup table.
Then for an onValueEdit event on the CATEOGRY drop down I have a script to reload the CATEGORY_MATRIX table source based on the value of the CATEGORY drop down in the query so when the CATEGORY is selected only valid SUB_CATEGORY options are shown in the second drop down.
var datasource = app.datasources.CATEGORY_MATRIX
datasource.query.filters.CATEGORY._equals = newValue;
datasource.load();
There may be more efficient ways to do this but the benefit is I could create another form page and dynamically add new combos so there isn't any required code change as new combos are needed.
I have a grid which for some reasons I added dynamically a combobox. I have done it and working like charm.
The next thing which I am stack is how to set the selection for each row per code.
for example in first row of the gird the combobox I want to has the value X and in the second row I would like to has the value Y.
FormGridControl grid = sender.formRun().design(0).controlName('FormGridControl1');
ColumnTable columnTable;
ValueTable valueTable;
while select * from columnTable
{
FormComboBoxControl combo1 = grid.addControl(FormControlType::ComboBox,columnTable.Name);
combo1.label(columnTable.Name);
combo1.enumType(enumNum(enumValue));;
combo1.registerOverrideMethod(methodStr(FormComboBoxControl, SelectionChange),'DynamicComboControl_SelectionChanged',this);
while select * from valueTable
where valueTable.ColumnName == columnTable.Name
{
// at this place I have to set the values of the combo1 for each line of the grid separately.
// and I have not any idea how I can do this.
}
}
Can someone help me please?
You never assigns values to grid fields using a loop.
If the data in your field in the grid comes from a field of the datasource then use a bound field (maybe created dynamically by addDataField).
fc = grid.addDataField(fbds.id(), fieldNum(MyTable,MyField));
If your data field can be computed by some method add a display method.
Added dynamically like this:
name = tableMethodStr(MyTable,myMethod);
fc = grid.addControl(FormControlType::ComboBox, ds.name()+'_'+name);
fc.dataSource(grid.datasource());
fc.dataMethod(name);
If your data can be edited, then the method must be an edit method. Added dynamically the same way as a display method.
IF your grid have not binded to a datasource
THEN table.cell(col,row).data()...
see tutorial_Form_Table form.
IF your grid have binded to a datasource
THEN create and fill records in the your table and research() the datasource on the form.
Use Selection(i) method if you looking method for FormComboBoxControl.
https://msdn.microsoft.com/ru-ru/library/aa499256(v=ax.50).aspx
I am trying to filter a table using a DateBox. The problem I have is that it doesn't display the records of that day when binding value is set to #datasource.query.filters.date._equals. However, it does work when the filter is _greaterThanOrEquals, but it also includes later records.
I am using SQL tables with date field type is DATE.
It's a bug. We're looking into it.
For now please use workaround:
Remove the binding and set 2 filters in onValueEdit event with code like:
widget.datasource.query.filters.FIELD_NAME._greaterThanOrEquals = newValue;
widget.datasource.query.filters.FIELD_NAME._lessThanOrEquals = newValue ? new Date(newValue.getTime() + 24*60*60*1000) : null;
widget.datasource.load();
bind DateBox value to
#datasource.query.filters.NameOfDateFiled._equals
and don't forget reload datasource in "onValueChange" event.
In the form cutslistepage , i want to get the value of accountNum of the selected row in grid and passe it to another form
i have try that :
int64 recordsCount;
recordsCount = CustTable_ds.recordsMarked().lastIndex();
// CustTable = CustTable_ds.getFirst(1);
If you want to retrieve the CustTable record, check the CustTableListPageInteraction class.
In the selectionChanged method, it has the following code:
custTable = CustTable::findRecId(this.listPage().activeRecord(queryDataSourceStr(CustTableListPage, CustTable)).RecId);
This is how you can retrieve the record. But since it is already done, you can simply use the custTable variable that is already declared in the class declaration.
Side note: if you have an other form that is opened from the list page, it should automatically be filtered based on the relations between the data sources of the form. So you might be searching for a solution for a problem you shouldn't have. For example create a form that has a data source with a relation to the CustTable table on it and it should create a dynaink between the list page and your form, filtering the records for that customer.
If only one record is selected you can do:
info(CustTable_ds.accountNum);
Otherwise, if more than one record is selected you need to do something like:
custTable = CustTable_ds.getFirst(true);
while (custTable)
{
info(custTable.accountNum);
custTable = CustTable_ds.getNext();
}
In a customised form I would have a create Purchase Menubutton which opens a dialog to create a purchase order.
But I need to select few records like one or two lines and then create purchase order only for those records. How do I do that?
Take a look on the "Create purchase order" button on the SalesTable form.
It works differently: you select the lines to purchase after you press the button, but it might work in your case also.
Also have a look on how to use multiple selected records in a grid.
Here is a piece of code which allows you to get the record from the previous form.
You have to put this piece of code in the INIT method of the dialog. So you have to override the init of the dialog.
DmoVehicleTable vehicleTable;
DmoVehicleId vehId;
// Get the vehicle ID from the previous form
if (element.args() && element.args().record())
{
switch (element.args().record().TableId)
{
case (tableNum(DmoVehicleTable)):
vehicleTable = element.args().record();
vehId = vehicleTable.VehicleId;
break;
default:
throw error (strFmt("#SYS477", this.name()));
}
}
I hope this will help you.
If you need more help: http://sirprogrammer.blogspot.com/