Recently found this issue on an internal forum and found the solution given by Jobinesh.. Thought I could share the info here
Problem description:
“I’m trying to apply a view criteria programmatic way here. When the bind variable for “StartDate” (which is a VO attribute) uses just a “=”. then at runtime the VC gets appended to the query using a TO_DATE for the bind var, which is as expected. However, when the bind variable for “StartDate” uses just a “>=” / “<“>” . then at runtime the VC gets appended to the query using a TO_CHAR for the bind var, which is not that we require. Is there any way to get a TO_DATE for this kind of comparison as well?”
Please take a look at the following sample method :-
public Row getSampleHeaderVORecord(Date activeDate) {
ViewObjectImpl SampleHeaderVO = getSampleHeader1();
ViewCriteria viewCriteria = SampleHeaderVO.createViewCriteria() ;
ViewCriteriaRow vcr1 = viewCriteria.createViewCriteriaRow() ;
vcr1.setAttribute("StartDate", ">="+(activeDate.));
viewCriteria.add(vcr1);
SampleHeaderVO.applyViewCriteria(viewCriteria);
SampleHeaderVO.executeQuery();
return SampleHeaderVO.next();
}
Do let me know.
Sample query that appears at runtime :-
SELECT *WHERE ( ( (TO_CHAR( ForecastHeaderEO.START_DATE, 'yyyy-mm-dd') > '0007-04-02' ) ) )
The TO_CHAR in the last line is what I’m referring to. Is there any way to get a TO_DATE there?
Solution:
ViewObjectImpl SampleHeaderVO = getSampleHeader1();
ViewCriteria viewCriteria = SampleHeaderVO.createViewCriteria() ;
ViewCriteriaRow vcr1 = viewCriteria.createViewCriteriaRow() ;
ViewCriteriaItem vci = vcr1.ensureCriteriaItem("StartDate");
vci.setOperator(JboCompOper.OPER_ON_OR_AFTER);
vci.setValue(activeDate);
viewCriteria.add(vcr1);
SampleHeaderVO.applyViewCriteria(viewCriteria);
SampleHeaderVO.executeQuery();
Like this:
Like Loading...