NetTalk Central

Author Topic: A simple Formula in a form  (Read 8026 times)

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
A simple Formula in a form
« on: October 15, 2017, 07:28:08 AM »
Hi friends,

File Name: Product
Field:
- ProductName
-Price (Display)
-Discount (Number)
-AmountToPay (Display)

i have a form with a lookup for a product. once the product selected, the Price is automatically assigned. The default discount is zero. Thus, when i select the product, the AmountToPay should be automatically calculated.
Example, if the price is USD 150, then AmountToPay should be USD 150.

Where should i put the embed for it?

Also, when the Discount is keyed in, the AmountToPay should be automatically recalculated. How do i make it happen?

So far, i only manage to save the AmountToPay after the user press the Save button. Thus, the value is only reflected in the AmountToPay when i return to browse.

regards,
Jason

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #1 on: October 15, 2017, 08:35:37 AM »
Look for ValidateValue::AmountToPay .

Set your Discount field to refresh the "value" for your AmountToPay

Do your math in the ValidateValue::AmountToPay embed.

Voila!
« Last Edit: October 15, 2017, 08:52:33 AM by DonRidley »
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: A simple Formula in a form
« Reply #2 on: October 16, 2017, 03:25:56 AM »
Hi,

When you are in the template, goto "Send new value to the server" on one of the tabs.
Select the check-box and click the "Server side code" button.
An embed will be shown, select the bottom line and click source.
Enter the code you want to be executed to calculate the amounts this can include file access and all, but keep in mind that while this is executing, the user has to wait to get the result presented.
Put the values in the session value queue using the equates you defined with the fields (most are the same as the field names but be carefull)
close the source embeditor add the equates to the reset fields.

If you don't reset the fields or don't use the session values for the equates, you might mot see the result, on your form.

It seems like a lot of work but when you get used to it, it's a breeze. And the effect is stunning.

Cheers,
 Rene
Rene Simons
NT14.14

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #3 on: October 16, 2017, 04:46:40 AM »
Hi Dan,
Thank you for the suggestion. I have tried the method:

I have put the following line :

AmountToPay = Amount - DiscountRate

in embed point of AmountToPay field

Routines - Tab - AmountToPay - 2ValidateValueRoutine - Start


and still it doesnt work.

:-(

 

Look for ValidateValue::AmountToPay .

Set your Discount field to refresh the "value" for your AmountToPay

Do your math in the ValidateValue::AmountToPay embed.

Voila!


ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #4 on: October 16, 2017, 04:49:30 AM »
Hi Rene,
I have tried your method this way:

I create a button call Apply Discount.
In that button template, i select at Client Side  - send new value - and check server side code and put the following code in the embed point:

  p_web.SSV('ACM:DiscountRate',50)
    ACM:AmountToPay = ACM:Amount - ACM:DiscountRate
   
    p_web.SSV('ACM:AmountToPay',ACM:AmountToPay)


The first line definitely works because it is pretty straight forward. But other lines not working.
Also, i did put the reset field of both field and even tried putting AmountToPay only value reset.
Still the same.
Doesnt work.

:-(


Hi,

When you are in the template, goto "Send new value to the server" on one of the tabs.
Select the check-box and click the "Server side code" button.
An embed will be shown, select the bottom line and click source.
Enter the code you want to be executed to calculate the amounts this can include file access and all, but keep in mind that while this is executing, the user has to wait to get the result presented.
Put the values in the session value queue using the equates you defined with the fields (most are the same as the field names but be carefull)
close the source embeditor add the equates to the reset fields.

If you don't reset the fields or don't use the session values for the equates, you might mot see the result, on your form.

It seems like a lot of work but when you get used to it, it's a breeze. And the effect is stunning.

Cheers,
 Rene

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #5 on: October 16, 2017, 04:52:00 AM »
just to give a clearer picture of how my form looks..

attached is the pic.

jason

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #6 on: October 16, 2017, 07:44:16 AM »
What about:

In ValidateValue::AmountToPay

p_web.SSV('ACM:AmountToPay', p_web.GSV('ACM:Amount') - p_web.GSV('ACM:DiscountRate'))

Do a refresh of the ACM:AmountToPay in the ACM:DiscountRate field.

I cannot remember if p_web.SSV will let you do that but I think it will.

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: A simple Formula in a form
« Reply #7 on: October 16, 2017, 12:05:09 PM »
Hi,

I have created a small document that may be of help.
Btw NEVER do calculations using Session Queue Values.
In some cases unpredictable results may occur. There is an item on this in this forum.
Just use the genuine field names and store the outcome them in the session value queue after calculating.

This is also better to read at a later time.

Cheers,
Rene


Rene Simons
NT14.14

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #8 on: October 16, 2017, 02:03:19 PM »
Good to know Rene.  I wasn't sure about that.

"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #9 on: October 16, 2017, 06:37:01 PM »
Hi Don and Rene,
Thank you very much for the reply and fine notes. Appreciate that.

I have tried the method in pdf closely and it still dont work.

    p_web.SSV('ACM:DiscountRate',50)
    ACM:AmountToPay = ACM:Amount - ACM:DiscountRate
   
    p_web.SSV('ACM:AmountToPay',ACM:AmountToPay)
   ! p_web.SSV('ACM:DiscountRate',ACM:DiscountRate)


In fact, after i disable the last line, then the Discount rate works. And yes, i have check the equates. it is correct.


I put the simple line: ACM:AmountToPay = ACM:Amount - ACM:DiscountRate
in the Validate - ACM:DiscountRate embed point.
After pressing ok, then it saves the value which i can see in the browse.

I have checked the examples by bruce and all of them show the total in the browse. Not form itself.

Jason

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: A simple Formula in a form
« Reply #10 on: October 16, 2017, 09:40:01 PM »
Hi,
Session queue values are not the same as variables. They are just a place to store you variable values.
Change your first line to
ACM:Discountrate = 50

Then uncomment the last line.
That should work

Rene
Rene Simons
NT14.14

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: A simple Formula in a form
« Reply #11 on: October 16, 2017, 10:30:27 PM »
Hi,
Extra comment:
The values in the browse are from your database.
The values in your form are the result of the way you conduct your calculations.
In this case, that is.

Rene
Rene Simons
NT14.14

ntnewbies

  • Full Member
  • ***
  • Posts: 184
    • View Profile
    • Email
Re: A simple Formula in a form
« Reply #12 on: October 17, 2017, 02:32:06 AM »
Thanks Rene,
The discount rate comes up. It gives me clue on how to do the rest of the code.
Thank you once again to both Dan and Rene



Jason