最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to call Javascript from inside a PLSQL code in dynamic action of oracle apex - Stack Overflow

programmeradmin1浏览0评论

How can we call javascript code from a PLSQL code in dynamic action of Oracle apex. Actually, my requirement is to select a Role(P2_ROLE) from a dropdown list. And than find all the usernames attached to this role using sql query. Once the usernamess are retrieved, all the rows in interactive grid should get coloured for these list of users. The IG contains a column name USER_NAME.

If The role is present in the IG, than I can make it work by writing the below code in dynamic action ---> Javascript code

     $(document).ready(function() {
$("td:nth-child(28)").each(function() {
    if ($(this).text() === apex.item( P2_ROLE ).getValue()) {
        $(this).parent().children().css({'background-color': '#FF9999'});
    }       
});
});

But the issue is the Role that is picked up is not displayed in the interactive grid.

So as a workaround, I want to fetch all the usernames specific to that role using PLSQL and match them with the USER_NAME column in interactive grid using JAVASCRIPT.

But I am not sure how can I call JAVSCRIPT code in a PLSQL code. Basically I want to do something like this :

DECLARE
Cursor c_user_name is
 select distinct user_name  from wf_user_roles where role_name = :P2_ROLE;
l_USER_NAME varchar2(1000);
BEGIN
 OPEN C_USER_NAME ;
  LOOP
   FETCH C_USER_NAME into l_USER_NAME;
   EXIT WHEN C_USER_NAME%NOTFOUND;

  -- Call this JAVASCRIPT code now  
  /*
  $(document).ready(function() {
   $("td:nth-child(28)").each(function() {
    if ($(this).text() === l_USER_NAME) {
        $(this).parent().children().css({'background-color': '#FF9999'});            

     }        
   });
  });
 */

 END LOOP; 
 END;

Can somebody please help me regarding this.

How can we call javascript code from a PLSQL code in dynamic action of Oracle apex. Actually, my requirement is to select a Role(P2_ROLE) from a dropdown list. And than find all the usernames attached to this role using sql query. Once the usernamess are retrieved, all the rows in interactive grid should get coloured for these list of users. The IG contains a column name USER_NAME.

If The role is present in the IG, than I can make it work by writing the below code in dynamic action ---> Javascript code

     $(document).ready(function() {
$("td:nth-child(28)").each(function() {
    if ($(this).text() === apex.item( P2_ROLE ).getValue()) {
        $(this).parent().children().css({'background-color': '#FF9999'});
    }       
});
});

But the issue is the Role that is picked up is not displayed in the interactive grid.

So as a workaround, I want to fetch all the usernames specific to that role using PLSQL and match them with the USER_NAME column in interactive grid using JAVASCRIPT.

But I am not sure how can I call JAVSCRIPT code in a PLSQL code. Basically I want to do something like this :

DECLARE
Cursor c_user_name is
 select distinct user_name  from wf_user_roles where role_name = :P2_ROLE;
l_USER_NAME varchar2(1000);
BEGIN
 OPEN C_USER_NAME ;
  LOOP
   FETCH C_USER_NAME into l_USER_NAME;
   EXIT WHEN C_USER_NAME%NOTFOUND;

  -- Call this JAVASCRIPT code now  
  /*
  $(document).ready(function() {
   $("td:nth-child(28)").each(function() {
    if ($(this).text() === l_USER_NAME) {
        $(this).parent().children().css({'background-color': '#FF9999'});            

     }        
   });
  });
 */

 END LOOP; 
 END;

Can somebody please help me regarding this.

Share Improve this question asked Oct 3, 2018 at 11:37 AbhaAbha 3473 gold badges12 silver badges31 bronze badges 1
  • related question: stackoverflow./questions/52613246/… – romeuBraga Commented Oct 3, 2018 at 20:19
Add a ment  | 

1 Answer 1

Reset to default 4

You can use apex.server.process:

https://docs.oracle./cd/E71588_01/AEAPI/apex-server-namespace.htm#AEAPI30050

With this function you can call a PL/SQL process with javascript and do something after this code return something.

Example: https://munity.oracle./thread/4094475

UPD.

JAVASCRIPT

apex.server.process("new_assign_roles", 
   { x01: 'a_value', x02: 'b_value', x03: 'c_value' },
   {
      success: function(pData) {
         //you can do anything here
         console.log(pData);
         apex.message.alert(pData.v_result);
      }
   }
);

ON DEMAND PROCESS

DECLARE

p_a VARCHAR2(1000) := APEX_APPLICATION.g_x01; 
p_b VARCHAR2(1000) := APEX_APPLICATION.g_x02; 
p_c VARCHAR2(1000) := APEX_APPLICATION.g_x03; 

v_result VARCHAR2(4000) := p_a||' - '||p_b||' - '|| p_c;

BEGIN 
-- you can do anything here  

    apex_json.open_object;  
    apex_json.write('success', true);  
    apex_json.write('v_result', v_result);  
    apex_json.close_object;  

END;

You can see this example here:

https://apex.oracle./pls/apex/f?p=145797:33

login with:
workspace: stackquestions
user: user_test
pwd: stackquestions
application: 145797
page: 33

20191125AL > User user_test is locked.

发布评论

评论列表(0)

  1. 暂无评论