Translate

Saturday, February 25, 2012

Initialize the query in the report

We will assume the table as AssetTable( where the report is based on AssetTable), then write the code in init() method as
public void init()
{
    if(this.args().dataset() == TableNum(AssetTable))
    {
        AssetTable = this.args().record();
    }
    super();
}

Write the InitQuery() to initialize the query which is as follows..

public Query initQuery(Query _query)
{
    QueryBuildRange range;
    ;
    query = _query;
    if (AssetTable)
    {
        range = query.dataSourceTable(tablenum(AssetTable)).findRange(fieldnum(AssetTable,AssetId));
        if (!range)
            range = query.dataSourceTable(tablenum(AssetTable)).addRange(fieldnum(AssetTable,AssetId));
        range.value(AssetTable.AssetId);

or

SysQuery::findOrCreateRange(query.dataSourceTable(tablenum(AssetTable)), fieldnum(AssetTable, Assetid)).value(queryvalue(AssetTable.AssetId));
    }
    return query;
}

Now fi you call this specified report from the form which is based on Asset Table, then the report will run for specific Asset number.

// To avoid the usage data when called from Fixed Assets form(This will stop the usage data updates)
public boolean mustLoadSaveQuery()
{
    if (AssetTable)
    {
        return false;
    }
    else
    {
        return true;
    }
}
Thanks, and hope It will helps you.

Monday, February 13, 2012

How to identify the Table associted with called map

<MapName>.TableId == TableNum(TableName) will be able to identify the table which is called to this map.
Ex: In addressmap, there are so many tables mapped, but to update the address only one table is called at a time like CustTable, So to identify whether it is called from custTable, then

we write code as
if(AddressMap.TableId == TableNum(CustTable))
{
info("Cust Table is called to map");
}
else
{
info("Other than custTable, the map is called");
}