Counting records in object based on relationship

Posted by mgill on 07-Oct-2014 09:07

Hi, I have a building sites object (site) which I can add building plots (plot). Relationship is many plots to a single site. However, I shouldn't be able to add the same plot number to a site twice. Am testing some validation on the "add new" plot page which does a count of the plots in the database with the plot number entered and the site (site is a hidden relationship field on the page). Plot no is character field. Integration name for the relationship field on plot for the site is R110925246. testing this on the pagesubmit event: alert(document.getElementById('plot_no').value); alert(document.getElementById('R110925246').value); var count = rbv_api.selectNumber("SELECT COUNT(1) FROM plot WHERE plot_no = '?' AND R110925246 = ? ", document.getElementById('plot_no').value, document.getElementById('R110925246').value); alert(count); First two alerts come back with a value, but the count does not show an alert. What am I doing wrong?

Posted by Godfrey Sorita on 07-Oct-2014 13:59

Can you provide more information on your problem? I can only reproduce this issue when I disable the portal visitor role permissions and then run the script on a portal page. Thanks.

All Replies

Posted by Godfrey Sorita on 07-Oct-2014 09:37

Since you're running the script on a page event, you should consider using Client-side AJAX API instead of a Server-side API. Please replace rbv_api.selectNumber() with rbf_selectNumber() to make the code work.

For more information regarding Client-side AJAX APIs please check this link: http://documentation.progress.com/output/NewFolder/index.html#page/Intro/chapter7.08.01.html

Posted by mgill on 07-Oct-2014 12:29

Hi, Tried this on the onsubmit event on the page. Still no luck. Tried the simple code example below to show a message counting the number of records in the plot object, but count is always returned as 0. I know there is 10 records in the plot object.

var qry = "SELECT COUNT(1) FROM plot";

alert('Qry='+qry);

rbf_selectNumber(qry, callback_count);

function callback_count(querycount) {

alert('Count='+querycount);

}

Posted by Godfrey Sorita on 07-Oct-2014 13:59

Can you provide more information on your problem? I can only reproduce this issue when I disable the portal visitor role permissions and then run the script on a portal page. Thanks.

Posted by Aede Hoekstra on 08-Oct-2014 07:11

Why don't you use autonumbering on the plot object?

Posted by Godfrey Sorita on 09-Oct-2014 14:07

Hi Manjinder,

Since you've verified this as an answer to your problem, I'm assuming the solution is to enable portal visitor permissions.

Also, please keep in mind that the number of client-side API calls is limited per login session (Default: 1,000). If you're querying records without a filter, then you can use server-side API which is faster and more reliable. #EVAL[] block can be used to execute server-side APIs on Rollbase pages.

This thread is closed