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.


Tuesday 17 February 2015

Product Attribute Value


Feed the method with an itemid and the attribute name and get back the value of the attribute (if it exists)


public str getProductAttribute(ItemId _itemId, Name _attributeName)
{
    inventTable                 InventTable;
    EcoResProductAttributeValue ecoResProductAttributeValue;
    EcoResAttribute             ecoResAttribute;
    EcoResValue                 ecoResValue;

     select InventTable where InventTable.itemid == _itemId
        join RecId from ecoResProductAttributeValue
        where ecoResProductAttributeValue.Product == InventTable.Product
            join Name from ecoResAttribute
            where ecoResProductAttributeValue.Attribute == ecoResAttribute.RecId &&
                  EcoResAttribute.Name == _attributeName
                join ecoResValue
                where ecoResValue.RecId == ecoResProductAttributeValue.Value;

    return ecoResValue.value();

}