Sign Up

Hey, Dev!
Are you looking for a forum full of active developers to help you?
So if you want to:
➡️ Get answers for your development issues
➡️ Help others
➡️ Write an article
➡️ Get rewarded for your active participation
Then this place is just for you and it is 100% FREE.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have a permission to ask a question, You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

OrclQA.Com

OrclQA.Com Logo OrclQA.Com Logo
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Blog
  • New Questions
  • Tutorials
    • Oracle
    • Oracle Apex
    • Python
  • Tags
  • Users
  • Badges & Points
  • About
Home/Questions/Q 6112
In Process
Bansari
Bansari

Bansari

  • 1 Question
  • 8 Answers
  • 0 Best Answers
  • 27 Points
View Profile
  • 1
BansariContributor
Asked: March 26, 20212021-03-26T23:39:25+05:30 2021-03-26T23:39:25+05:30

How to have an APEX item with arithmetic ability in APEX 19.1

  • 1

For example:
I’m having an item :P1_SALES
And I want to enter 1000+2000-1000
And it will give me 2,000 on the same item :P1_SALES

Note I’m using a plug-in(AutoNumeric) for my input format

question
  • 14
  • 149
  • 0
  • 0
  • Share
    • Share on Facebook
    • Share on Twitter
Answer

    14 Answers

    1. Vinish

      Vinish

      • 1 Question
      • 547 Answers
      • 53 Best Answers
      • 3k Points
      View Profile
      Vinish Enlightened
      2021-03-27T06:59:08+05:30Added an answer on March 27, 2021 at 6:59 am

      To do this, create a dynamic action on P1_SALES on Lose Focus event and create a true action to execute JavaScript code as follows:

      var c;
      c = eval($v("P1_SALES"));
      $s("P1_SALES", c);

      Save the changes and test.

      • 1
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
      • Bansari

        Bansari

        • 1 Question
        • 8 Answers
        • 0 Best Answers
        • 27 Points
        View Profile
        Bansari Contributor
        2021-03-28T23:21:05+05:30Replied to answer on March 28, 2021 at 11:21 pm

        Thank you so much for quick response.
        This is working perfectly fine.
        Just one thing is that I couldn’t implement it with AutoNumeric Plug-in.
        It’s provide only one number input, whenever I try to input 2 numbers with + or - sign it is taking it as a negative positive number differentiation.
        And I really need that plug-in in order have flexibility for number format.
        Can anyone please help me with it.

        • 1
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
        • Vinish

          Vinish

          • 1 Question
          • 547 Answers
          • 53 Best Answers
          • 3k Points
          View Profile
          Vinish Enlightened
          2021-03-29T08:54:51+05:30Replied to answer on March 29, 2021 at 8:54 am

          You can use the Text Field item instead of Numeric and disable the AutoNumeric for this field and use the below expression in the Text Field item's > Advance > Custom Attributes section:

          onfocusout="this.value=Number(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')"

          The above expression will format the number.

          • 1
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
          • Bansari

            Bansari

            • 1 Question
            • 8 Answers
            • 0 Best Answers
            • 27 Points
            View Profile
            Bansari Contributor
            2021-04-01T03:19:07+05:30Replied to answer on April 1, 2021 at 3:19 am

            Hello,

            thanks, for the solution.
            Now everything is working step by step.
            I'm right now on the last step of fulfilling the requirement.
            I did apply both above step and using this now the last part is addition of 2 fields with the same behavior I mentioned above.
            I used JavaScript solution of yours' (https://www.foxinfotech.in/2020/02/oracle-apex-calculate-field-values-using-javascript.html)
            But now all three fields working differently:
            1. P1_SALES, P1_COST (TEXTFIELD with 2 steps mentioned above)
            2. P1_PROFIT (TEXTFIELD with JavaScript solution mentioned in this message with link) - Formula set in JS (P1_SALES - P1_COST)

            Now when trying to input in P1_SALES: 1000+2000
            it gives 3000 in P1_PROFIT
            but when I did put 1000 in P1_COST
            it gives 1000(which is taking P1_COST value only) in P1_PROFIT and set P1_SALES to 0

            Please advise

            • 0
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
    2. Vinish

      Vinish

      • 1 Question
      • 547 Answers
      • 53 Best Answers
      • 3k Points
      View Profile
      Vinish Enlightened
      2021-04-01T07:54:00+05:30Added an answer on April 1, 2021 at 7:54 am

      Your JS function should be as below:

      function fnc_calcTotal() {
      var n_sales, n_cost, n_profit;
      n_sales = parseFloat($v("P1_SALES"), 10) ? parseFloat($v("P1_SALES"), 10) : 0;
      n_cost = parseFloat($v("P1_COST"), 10) ? parseFloat($v("P1_COST"), 10) : 0; 
      n_profit = n_sales - n_cost; 
      $s("P1_PROFIT", parseFloat(n_profit, 10));
      }

      Now call the above function fnc_calcTotal from P1_sales and P1_cost on lose focus event.

      • 1
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
      • Bansari

        Bansari

        • 1 Question
        • 8 Answers
        • 0 Best Answers
        • 27 Points
        View Profile
        Bansari Contributor
        2021-04-01T18:03:39+05:30Replied to answer on April 1, 2021 at 6:03 pm

        Yes I do have exact same function.
        Just difference is, I do have input type 1000+2000 and function in same dynamic action.

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
        • Bansari

          Bansari

          • 1 Question
          • 8 Answers
          • 0 Best Answers
          • 27 Points
          View Profile
          Bansari Contributor
          2021-04-01T19:37:16+05:30Replied to answer on April 1, 2021 at 7:37 pm

          I guess because I'm using
          onfocusout="this.value=Number(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')"
          as well on both the fields
          and then I do have 2 JS code implementing in dynamic action for both items.

          • 0
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
          • Vinish

            Vinish

            • 1 Question
            • 547 Answers
            • 53 Best Answers
            • 3k Points
            View Profile
            Vinish Enlightened
            2021-04-05T08:43:08+05:30Replied to answer on April 5, 2021 at 8:43 am

            Remove the onfocusout line from the custom attributes. I have added this line to the function. Now change the JS function as below and call it from P1_SALES and P1_COST:

            function fnc_calcTotal() {
             var n_sales, n_cost, n_profit;
             n_sales = eval($v("P1_SALES"));
             $s("P1_SALES", n_sales);
             n_sales = parseFloat(n_sales, 10) ? parseFloat(n_sales, 10) : 0;
             n_cost = parseFloat($v("P1_COST"), 10) ? parseFloat($v("P1_COST"), 10) : 0; 
             n_profit = n_sales - n_cost; 
             $s("P1_PROFIT", parseFloat(n_profit, 10));
            }

             

            • 1
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
            • Bansari

              Bansari

              • 1 Question
              • 8 Answers
              • 0 Best Answers
              • 27 Points
              View Profile
              Bansari Contributor
              2021-04-05T19:15:24+05:30Replied to answer on April 5, 2021 at 7:15 pm

              I tried below function

              function fnc_calcTotal() {
              var n_sales, n_cost, n_profit;
              n_sales = eval($v("P11_SALES"));
              $s("P11_SALES", n_sales);
              n_cost = eval($v("P11_COST"));
              $s("P11_COST", n_cost);
              n_sales = parseFloat($v("P11_SALES"), 10) ? parseFloat($v("P11_SALES"), 10) : 0;
              n_cost = parseFloat($v("P11_COST"), 10) ? parseFloat($v("P11_COST"), 10) : 0;
              n_profit = n_sales - n_cost;
              $s("P11_PROFIT", parseFloat(n_profit, 10));
              }

              Removed custom attribute and eval function from both P11_SALES and P11_COST as you mentioned
              But, it is not giving me P11_PROFIT calculated and, Where can I add format part as I have to implement it?

              Thanks

              • 0
              • Share
                Share
                • Share on Facebook
                • Share on Twitter
    3. Vinish

      Vinish

      • 1 Question
      • 547 Answers
      • 53 Best Answers
      • 3k Points
      View Profile
      Vinish Enlightened
      2021-04-07T07:59:01+05:30Added an answer on April 7, 2021 at 7:59 am

      I have tested the above code and it is working completely fine.

      After creating that function in Function and Global Variable declare section and I am simply calling it using dynamic action on losing focus event by executing the JS code as below:

      fnc_calcTotal();
      • 1
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
      • Bansari

        Bansari

        • 1 Question
        • 8 Answers
        • 0 Best Answers
        • 27 Points
        View Profile
        Bansari Contributor
        2021-04-07T08:45:40+05:30Replied to answer on April 7, 2021 at 8:45 am

        Ok, I can double check my function and fields,
        But please let me know how to achieve format within those numbers as it is equal important for me with this arithmetic ability.
        I have tried “ Number(this.value).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')"
        within function.

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
        • Vinish

          Vinish

          • 1 Question
          • 547 Answers
          • 53 Best Answers
          • 3k Points
          View Profile
          Vinish Enlightened
          2021-04-07T14:59:25+05:30Replied to answer on April 7, 2021 at 2:59 pm

          We can specify the format to the P1_SALES, but it will be an issue in calculating values then.

          • 1
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
          • Bansari

            Bansari

            • 1 Question
            • 8 Answers
            • 0 Best Answers
            • 27 Points
            View Profile
            Bansari Contributor
            2021-04-07T16:59:58+05:30Replied to answer on April 7, 2021 at 4:59 pm

            Yes, you are right, I tried but it’s not calculating values.
            Is there any other way?
            Format mask also not supporting.
            And tried plug-ins too, but those ones are not allowing me to enter numbers like 1000-500.

            • 0
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
          • Bansari

            Bansari

            • 1 Question
            • 8 Answers
            • 0 Best Answers
            • 27 Points
            View Profile
            Bansari Contributor
            2021-04-08T19:38:43+05:30Replied to answer on April 8, 2021 at 7:38 pm

            Please help me out to close this as it is getting crucial for my project.

            Thanks in advance for all your extra effort.

            • 0
            • Share
              Share
              • Share on Facebook
              • Share on Twitter

    You must login to add an answer.

    Forgot Password?

    Sidebar

    Ask Question
    Write a Post

    Recent Blog Posts

    • Vinish

      Oracle Apex - Display External File in Region

    • Vinish

      Oracle PL/SQL Download BLOB File to Disk

    • Vinish

      Oracle Convert External File to BLOB

    • Vinish

      Oracle Apex Calendar Example

    • Vinish

      Oracle Apex - Open Modal Dialog Page Using JavaScript

    Explore

    • Home
    • Blog
    • New Questions
    • Tutorials
      • Oracle
      • Oracle Apex
      • Python
    • Tags
    • Users
    • Badges & Points
    • About

    © 2021 OrclQA.Com. All Rights Reserved. Privacy Policy