1 2 Previous Next 15 Replies Latest reply: Oct 7, 2013 7:22 AM by backintheday RSS

    Assigning a value to a number field through a button

    salute-Salem

      11gxe , apex 4.x ,

      hi all ,

      i am trying to assign value to a number field through a button ,

      i created a button , then a dynamic action for this button , when it is clicked ,

      the dynamic action is based on Pl\Sql code , and the code is

       

       

      begin
      :p2_assign := 455 ; -- where the page is "p2" and the number field is "assign"
      end ; 
      

       

      but it does not work , why ?

        • 1. Re: Assigning a value to a number field through a button
          Ramesh P, Oracle APEX Developer

          Create a DA

          select onclick of button

           

          set value as action

           

          select the element that needs to get set also

          You return your values back

          • 2. Re: Assigning a value to a number field through a button
            backintheday

            Is your number field "assign" or "p2_assign"?  To match your code, it needs to be the latter.

            • 3. Re: Assigning a value to a number field through a button
              salute-Salem

              it's correct , but why my code does not work ,

              can not i do it with pl\sql code ?

              if yes , how to do it ?

               

              2- why can not i do this also : -- by the pl\sql code action as well

               

              begin
              select 455 into :p2_no from dual ;
              end ; 
              

              ??

              thanks

              • 4. Re: Assigning a value to a number field through a button
                backintheday

                I have created a quick demo for you:

                 

                http://apex.oracle.com/pls/apex/f?p=61075:2

                workspace: work_ws

                username: demo

                password: demo

                 

                If you only need to set a static value on a button click, this is the way to do it.  Let me know if you have any questions.

                • 5. Re: Assigning a value to a number field through a button
                  salute-Salem

                  I have created a quick demo for you:

                  thanks , but i can not see the developers toolbar , to see how you did it .

                   

                  If you only need to set a static value on a button click

                  no , i just need to learn how to deal with pl\sql code if i need to assign a static or not static or a value of a variable to an item on a button click ?

                  i want to know why my code does not work ?

                   

                   

                  thanks

                  • 6. Re: Assigning a value to a number field through a button
                    backintheday

                    The DEMO user is a developer.  If you go to http://apex.oracle.com/pls/apex/f?p=4550 and use the credentials I supplied, you should see it.

                     

                    I'll get back to you tomorrow regarding how assigning static/dynamic values works.

                    • 7. Re: Assigning a value to a number field through a button
                      backintheday

                      Regarding your overall question about how to assign values to items in APEX via PL/SQL code, could you give specific examples of what you might need to assign to a given APEX item?

                      • 8. Re: Assigning a value to a number field through a button
                        salute-Salem

                        I can see the toolbar now from the last link you provided me with ,

                        but you showed me the way to use the static assigning , and assigning with sql , and i want to do it with "Pl\Sql"

                        in order to know why my way of writing the code does not work , although it is written properly , and should work .

                         

                        every input item is a variable , and i am doing so

                        begin  
                        :p2_assign := 455 ; -- where the page is "p2" and the number field is "assign"  
                        end ; 
                        
                        


                        to assign a value to a variable ,

                        and

                        doing this

                        begin  
                        select 455 into :p2_no from dual ;  
                        end ;   
                        
                        

                        to select a value into a variable , then

                        why does not it work ??

                        and how to do it with pl\sql ?

                         

                        thanks

                        • 9. Re: Assigning a value to a number field through a button
                          backintheday

                          I'm still not sure I understand exactly what you are asking, but let's give it a try anyway.  In order to assign a value for the page item P2_ASSIGN using PL/SQL, your code is actually doing this:

                           

                          :P2_ASSIGN := :p2_assign := 455;

                           

                          That won't work.  You just simply need to enter whatever that value is suppose to be.  You could do the following for the P2_ASSIGN page item:

                           

                          "Source: PL/SQL Expression"

                          REPLACE(:P2_OTHER_PAGE_ITEM,'abc','xyz');

                           

                          or

                           

                          "Source: PL/SQL Function Body"

                          DECLARE

                          l_string VARCHAR2(10);

                          BEGIN

                          SELECT 'abcdefg'

                          INTO l_string

                          FROM dual;

                          RETURN l_string;

                          END;

                           

                          Does that help?

                          • 10. Re: Assigning a value to a number field through a button
                            salute-Salem

                            The good news that you understand me correctly ,

                            my task is simply to assign a value for an item using Pl\Sql through a dynamic action .

                            your code is actually doing this:

                             

                            :P2_ASSIGN := :p2_assign := 455;

                            why does it do so , when i wrote

                            :P2_ASSIGN := 455 ;

                             

                            this is the first thing .

                            the second is using the pl\sql through a dynamic action ,

                            i tried setting a value using pl\sql function through a computation and it worked , but does not when i use pl\sql code in a dynamic action ?

                            what does pl\sql code means ? does it mean pl\sql function or procedure or what ?

                             

                            p.s : when you create a dynamic action on a button , there is a step where you select the action you want to do ,

                            there is a type of action which is "Execute pl\sql code" , this what i am trying to use ,

                            how to use this action to set a value for an item ??? -- THIS IS THE QUESTION (ACCURATELY) .

                            • 11. Re: Assigning a value to a number field through a button
                              backintheday

                              Let's address the use of PL/SQL through a Dynamic Action (DA) and the True Action of Set Value.  There are 5 options: Static Assignment, JavaScript Expression, SQL Statement, PL/SQL Expression and PL/SQL Function Body.

                               

                              When you use the PL/SQL Expression option, you are setting up an anonymous block.  Therefore, whatever code you use here will set the value of the Page Item you reference in the "Affected Elements" .  So, the example I gave before is an anonymous block which sets a value for the Affected Element, P2_ASSIGN.  If P2_OTHER_PAGE_ITEM was holding a value of 'abcdefg', then your DA would set the value for P2_ASSIGN to become 'xyzdefg'.

                               

                              As for the PL/SQL Function Body option, could you show me the Function code you are trying to use in your Dynamic Action which worked fine in a Computation?

                               

                              **Note that whenever you are using "PL/SQL Expression" or "PL/SQL Function Body", the BEGIN/END keywords are automatically surrounding your code.  There is no need to add them unless you need an inner block after declaring variables or for catching exceptions, etc.

                              • 12. Re: Assigning a value to a number field through a button
                                Nicolette

                                Newby_egy

                                there is a type of action which is "Execute pl\sql code" , this what i am trying to use ,

                                how to use this action to set a value for an item ??? -- THIS IS THE QUESTION (ACCURATELY) .

                                The action "Execute pl/sql code" is setting your item on the server side. And this change is not not seen in the browser because client side doesn't know about this change there is nothing returned to the client.

                                The value of a item on the server is also called the session state of an item and can be seen by clicking on session on the developer bar.

                                This means that "Execute pl\sql code" is not the right dynamic action to see a value of an item change.

                                 

                                When changing a value of a item on the page the first thinking step is

                                What are you doing: => You are going to set the value => use dynamic action "Set value"

                                Where are you doing it => on the server side use the sql or pl/sql types

                                on the client side use the type javascript.

                                 

                                I hope this clears up some of the confusion that seems to be going on.

                                 

                                Nicolette

                                • 13. Re: Assigning a value to a number field through a button
                                  salute-Salem

                                  This means that "Execute pl\sql code" is not the right dynamic action to see a value of an item change.

                                  I am the server , it is one pc . it should work according to your words ?? why does not it work ?

                                  • 14. Re: Assigning a value to a number field through a button
                                    Nicolette

                                    Newbi_egy

                                     

                                    The physical location of the database cq server doesn't matter in this.

                                    Whether the server is on the other side of the world or on the same computer as the browser you are using.

                                    If you change the value of a page item using a dynamic action of type "Execute pl/sql code" the change will not be reflected on your page.

                                     

                                    As mentioned in my previous post use session to see the session state of the item. You will see that it has changed after you have run the dynamic action of type "Execute pl/sql code". If the popup is already open don't forget to refresh that page.

                                     

                                    If you want to change the value of the page item as you see it on the page then you have to use the type Set value as dynamic action.

                                     

                                    Nicolette

                                    1 2 Previous Next