Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Implementing an AJAX Callback which executes a query and returns 'YES' or 'NO'

M.EmmanuelJan 28 2019 — edited Jan 30 2019

I am trying to understand how AJAX Callbacks work.

I want to perform a DA when a Textfield loses focus IF a certain backend condition is met (i.e. I want to Execute Javascript that will check against an AJAX Callback process).

This is the Javascript code to execute:

apex.server.process(

    "MY_PROCESS",

    {

        pageItems: "#P302_COUNTRY_CODE"

    },

    {

        dataType: "text",

        success: function( pData ) {

            if (pData === 'YES') {

                console.log('YES');

                return(true);

            } else {

                console.log('NO');

                return(false);

            }

        }

    }

);

And this is the AJAX Callback (PL/SQL):

DECLARE

  pHasProvinces INTEGER;

BEGIN

  SELECT COUNT(*)

  INTO pHasProvinces

  FROM SUBDIVISION

  WHERE

      SUBDIVISION_LEVEL = 3 AND

      COUNTRY_CODE_ALPHA2 = :P302_COUNTRY_CODE;

 

  IF pHasProvinces > 0 THEN

      htp.p('YES');

  ELSE

      htp.p('NO');

  END IF;

 

END;

I have reviewed the documentation here. But unfortunately, I can not find an example on the PL/SQL process to implement.

Any help with the above code is welcomed. Also I am wondering if htp.p is the way to return a value in Apex18.

Apex 18.2.0.00.12

Oracle 18c XE

This post has been answered by shinotomo000401 on Jan 29 2019
Jump to Answer
Comments
Post Details
Added on Jan 28 2019
6 comments
5,164 views