Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Thursday, 19 February 2015

Query Build Range in Forms

Override the executeQuery() method the data source (on the Form/Data Sources/data source) to set the query. Note that the ranges are cleared before setting as they are persistent.

This example assumes that there is one datasource table, to make it easier;


public void executeQuery()
{  
    <variable definitions here>

    QueryBuildRange qbr;

    <dataNameOne> = element.design().controlName("<controlNameOne>").valueStr();
    <dataNameTwo> = str2enum(prodStatus,element.design().controlName("<controlNameTwo>").valueStr());
    <dataNameThree = str2enum(calcType,element.design().controlName("<controlNameThree>").valueStr());
    <dataNameFour> = str2enum(bomCalc,element.design().controlName("<controlNameFour>").valueStr());
    this.query().dataSourceTable(tableNum(<datasourceTable>)).clearRanges();
    qbr = this.query().dataSourceTable(tableNum(<datasourceTable>)).addRange(fieldNum(<datasourceTable>,<fieldNameOne>));
    qbr.value(<dataNameOne>);
    qbr = this.query().dataSourceTable(tableNum(<datasourceTable>)).addRange(fieldNum(<datasourceTable>,<fieldNameTwo>));
    qbr.value(strFmt("%1",<dataNameTwo>));
    qbr = this.query().dataSourceTable(tableNum(<datasourceTable>)).addRange(fieldNum(<datasourceTable>,<fieldNameThree>));
    qbr.value(strFmt("%1",<dataNameThree>));
    qbr = this.query().dataSourceTable(tableNum(<datasourceTable>)).addRange(fieldNum(<datasourceTable>,<fieldNameFour>));
    qbr.value(strFmt("%1",<dataNameFour>));
super();
}

Then change the trigger, in this case a click event, to run the execute the query above. Note the _ds extension, which denotes a datasource object.

void clicked()
{
    super();
    <datasourceTable>_ds.executeQuery();
}

This is not best practice, as you can build the range as a global object and add the values in the ranges in the executeQuery() method.


Monday, 6 October 2014

Multiline grid selection


When something is clicked, work through the grid to get just the selected lines (ticked or highlighted)

void clicked()
{
    CustPaymModeTable custPaymModeTablelocal;
    MultiSelectionHelper helper = MultiSelectionHelper::construct(); // construct the helper class
    helper.parmDatasource(custPaymModeTable_ds); // set the datasource of the helper
    custPaymModeTablelocal = helper.getFirst(); //get the first selected record of the helper

    while (custPaymModeTablelocal.RecId != 0)
    {
        info(custPaymModeTablelocal.PaymMode);
        custPaymModeTablelocal = helper.getNext(); //get the next selected record of the helper
    }
}


Thursday, 2 October 2014

Selective Data In Form Display



On the data sources section of the form ladder, under the data source, change the init method to select the data you require.

public void init()
{
    QueryBuildRange qryBuildRange;
    super();
    qryBuildRange = this.query().dataSourceName(this.name()).addRange(fieldNum(Addresses,AddressType));
    qryBuildRange.value(queryValue('D'));
    qryBuildRange = this.query().dataSourceName(this.name()).addRange(fieldNum(Addresses,dateCommited));
    qryBuildRange.value(queryValue(dateNull()));
    qryBuildRange.status(RangeStatus::Hidden);

}

The .Status being set to RangeStatus::Hidden stops the user over-ruling the selection manually.