Error in script

Posted by leonc on 13-Apr-2018 05:53

In a page I've added a script component that shows a page section if count of a view  is equals to zero.

<script>

function customizeEdit() {

var sectionID = rbf_getSectionIdByTitle("SectionName");

var myOrg = rbv_api.getCount("1122233456");

rbf_showOrHideSection(sectionID , myOrg===0);

}
</script>

The script is not working and in the console I get the following error: 

[ERROR] Page onload event handler ReferenceError: rbv_api is not defined

Posted by Srinivas Panyala on 13-Apr-2018 06:14

Please use below script

<script>

 function my_callback(myOrg)

{

 console.log(myOrg);

 var sectionID = rbf_getSectionIdByTitle("SectionName");

 rbf_showOrHideSection(sectionID, myOrg===0)

}

(function () {

rbf_getCount("6096",my_callback); // 6096 is view original id

})();

</script>

Thanks

Srinivas

All Replies

Posted by Ruben Dröge on 13-Apr-2018 05:58

You are using the server-side api for getCount. That won't work running client-side in the browser.

Replace it by the client-side one:

<script>

function customizeEdit() {

var sectionID = rbf_getSectionIdByTitle("SectionName");

var myOrg = rbf_getCount("1122233456");

rbf_showOrHideSection(sectionID , myOrg===0);

}
</script>

But maybe this one is more applicable to the use-case:

Posted by Ruben Dröge on 13-Apr-2018 06:01

You are using the server-side api for getCount. That won't work running client-side in the browser.

Replace it by the client-side one:

<script>

function customizeEdit() {

var sectionID = rbf_getSectionIdByTitle("SectionName");

var myOrg = rbf_getCount("1122233456");

rbf_showOrHideSection(sectionID , myOrg===0);

}

</script>

[View:https://documentation.progress.com/output/rb/doc/index.html#page/rb%2Frbf-getcount().html%23:550:50]

[View:https://documentation.progress.com/output/rb/doc/index.html#page/rb%2Frbf-getcount2().html%23:550:50]

But maybe this one is more applicable to the use-case:

[View:https://documentation.progress.com/output/rb/doc/index.html#page/rb%2Frbf-getviewcount.html%23:550:50]

Posted by Srinivas Panyala on 13-Apr-2018 06:14

Please use below script

<script>

 function my_callback(myOrg)

{

 console.log(myOrg);

 var sectionID = rbf_getSectionIdByTitle("SectionName");

 rbf_showOrHideSection(sectionID, myOrg===0)

}

(function () {

rbf_getCount("6096",my_callback); // 6096 is view original id

})();

</script>

Thanks

Srinivas

Posted by leonc on 13-Apr-2018 10:26

That worked perfectly.

Thank you very much Srinivas.

This thread is closed