How to add ranges to the form init method in COC?

Hi all,

this is the standard code. I want to add ranges(PurchId) to the Init method.

 class PurchLine
    {
        public void linkActive()
        {
            super();

            delete_from tmpFrmVirtualLines;
        }

        void init()
        {
            QueryBuildRange      rangeIsDeleted;
            QueryBuildDataSource queryBuildDataSource;

            super();

            queryBuildDataSource = this.query().dataSourceTable(this.table());
            queryBuildDataSource.clearDynalinks();
            rangePurchLine_VendAccount  = queryBuildDataSource.addRange(fieldNum(PurchLine, VendAccount));
            rangePurchLine_PurchStatus  = queryBuildDataSource.addRange(fieldNum(PurchLine, PurchStatus));
            rangePurchLine_ItemId       = queryBuildDataSource.addRange(fieldNum(PurchLine, ItemId));
            rangePurchLine_ProcurementCategory = queryBuildDataSource.addRange(fieldNum(PurchLine, ProcurementCategory));

            rangeIsDeleted = queryBuildDataSource.addRange(fieldNum(PurchLine,IsDeleted));
            rangeIsDeleted.value(SysQuery::value(NoYes::No));
            rangeIsDeleted.status(RangeStatus::Hidden);

            this.cacheAddMethod(tableMethodStr(PurchLine,pdsCWUnitId));
        }

Thank you

All right, but what do you need from us?
Does it mean that you know that you should use CoC but you have no idea how to create an extension class and extend init()? Or you know that and you have a problem with something else?

Hi Martin, Thanks for the reply.

I have no idea how to add ranges to init methods and executeQuery Methods using extension class. In mean while , i have tried some thing like the below code and it’s not working. this is the first time, i’m facing like this scenario.
could you please help me with this correct logic? and do we need to extend the executeQuery() method as well?

  public void init()    
    {  
        QueryBuildRange         purchLineQBR;
        QueryBuildDataSource    purchLineQBDS;
        
        next init();
        purchLineQBDS   = this.query().dataSourceTable(this.table());
       purchLineQBR      = purchLineQBDS.addRange(fieldNum(PurchLine, PurchId));
    }


}

Please never decribe your problems with mere “it’s not working”, because that tell us nothing. And we can’t help you if we don’t know anything about your problem.
For example, if you get an error, tell us whether it’s a compilation error or error at runtime, what the error message says and which line of code is throwing it.
Note that you’re referring to this.table(). Because table() method is defined on the data source, you must create a data source extension, not a form extension. Unfortunately you didn’t tell us what you did, therefore we can’t know which object you’re extending.

By the way, you could simply call this.queryBuildDataSource() instead of this.query().dataSourceTable(this.table()).

If you want to use form’s init(), refer to the data source by name:

public void init()    
{  
	next init();
	
	QueryBuildDataSource purchLineQbds = purchLine_ds.queryBuildDataSource();
	QueryBuildRange purchIdRange = purchLineQbds.addRange(fieldNum(PurchLine, PurchId));
	purchIdRange.value(queryValue("abc12345"));
}