Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 7355 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Oh I'm back. ooo.gif

You all helped me with this but I had to change it because they changed what they needed. Inserting percentage. They want buttons with 10-15-20 etc. AND NOW they also want to enter the percentage in the field directly. And then click Apply and change a dollar field or still click a number button like before.

I have buttons with script parameter of 10, 15, 20 etc. attached directly to the Apply Discount script. apply script would look at gDiscount (global text) and if it's empty, just use script parameter instead but if it has a value, use it instead. Make sense?

Modifying a prior calculation given me, I've come up with this. Oh please don't laugh. If price is 11.99 and I click 10% button (or have 10 in the gDiscount), it gives me ZERO!!!

Apply Discount script is:

Set Field [ Price; If(not IsEmpty(gDiscount); Round(Div(UnitPrice *

Filter(gDiscount; "0123456789"); 2);100);

Round(Div(UnitPrice * Get(ScriptParameter); 2); 100))

I put the filter because they keep wanting to type 10% or the words percent or put periods, but I couldn't make them all be consistent on what they entered so came up with this to strip everything. wink.gif

Part of this calc was before ... when my parameters were listed as .15 etc. and I tried to just extend on that logic, taking the whole percent and dividing by 100; but I don't understand it. Can someone help me figure it out? Thank you so much. smile.gif

Posted

Hi Bekah,

Just quickly looking at your script, it looks like you have your parameters mixed up. Right now, you're dividing by 2 and rounding out to 100 places. Swap the 2's and the 100's and see if that helps.

HTH

Adam

Posted

Thank you Adam! I didn't realize I had that backwards.

Well, now if Price is 23.29, and I click 10%, it converts it to 2.00. And if I put the 10 in the global, it also changes it to 2.00. Actually, it changes it to 2.

I wish percentages weren't so difficult for me. Can someone see what I have wrong? I verified 10 is in script parameter. I need the global to change to 23.29 minus 10%. Thank you!

Posted

You need to subtract the resulting percentage from the original Price to get the desired result. Try

Set Field [Price; UnitPrice - Round( Div( UnitPrice * If( IsEmpty(gDiscount); Get(ScriptParameter); Filter( gDiscount; "0123456789" ) ); 100 ); 2 )]

Posted

Oh that's perfect! I've spent hours on this. Geez, math is surely difficult. Thank you JT for helping me, especially since I know you're pressed at work right now. I appreciate it a lot. grin.gif

Posted

Mathematically speaking, 10% is actually 0.1, not 10. Get people to enter 0.1 into the field, but format the field to display as a percentage. They will soon realise their error if they type "10" because it will display as 1000%.

You could also use field validation to force the entey to be between 0 and 1 since you'll never have a discount greater than 100%.

  • 2 weeks later...
Posted

Well, I'm back I'm afraid. This is all working ... except when I click the 10 button. It's script paramter is 10. Is this the problem you're talking about Vaughan and Ugo? My Apply Discount script works on figuring all the discounts - except 10!!!! All the buttons work in any combination (between using the gDisplayDiscount field or clicking the buttons ... all except 10. And I just don't get it.

What I have:

Buttons with 10, 15, 20 etc.

Apply Discount Script is simple:

Set Field [ gUnitPrice; gHoldTempPrice - Round( Div( gHoldTempPrice * If( IsEmpty(gDisplayDiscount); Get(ScriptParameter); Filter( gDisplayDiscount; "0123456789" ) ); 100 ); 2 ) }

If I put a 50 in gDisplayDiscount it works - gUnitPrice changes right. Same with clicking the 50 button (it works) and works with all numbers but 10?:??

I made sure the 10 button is identical as the 50 except the number in the script parameter. I am at a total loss why it won't work - but that 10% is the MOST IMPORTANT!!! They are currently mad at me. Staff, I mean. crazy.gif

gDisplayDisc is global text, gHoldTempPrice is global number (with auto-enter do not replace) of gUnitPrice. And gUnitPrice is global number.

If you wonder why I'm using two global prices? Because otherwise if someone changed what discount was clicked, it would change the gUnitPrice (according to THAT price) instead of the original one. So I use a hold field to hold the 'original price' and compute off of that for discounts.

Oh, I hope there is help for me. wink.gif

Posted

I don't think you need two global prices. Just use a regular Price field to hold the result and an Original (or Unit) Price field to hold the original number. You wouldn't want TempPrice or UnitPrice to be a global or else it will be the same for all records and will overwrite one record's original price when a new one is created. In fact, now that I think about it, I wouldn't use globals at all or every record will also show the same discount to be applied.

I just tried the calc I used above (as you posted, but without the globals) and it seemed to work fine.

Posted

Thank you, JT. I'm using globals because the LineItem is written in Invoices before set in LineItems (many reasons for this) - namely because my validation script can't really validate until EVERYTHING has been entered and finalized on a lineitem. Then validation script checks the logic of it, against a set of 49 rules (rules table) before allowing it to write to LineItems.

Well, I originally only wanted them to use buttons but they then wanted to type right into discount field also. And my solution began to expand like urban sprawl, I think. Since I basically have to start over with this (because I can simply not find out why it won't work right on 10), maybe my buttons should just set the discount field when clicked, then staff click an Apply Discount button which uses that figure.

Are script parameters number or text? Maybe it's because I have a mix of number fields, text fields and script parameters? Well, I try re-writing it and see what happens. Wish me luck! grin.gif

Posted

Hi JT,

I changed the process so that clicking the button simply sets the gDiscount field with the script parameter (10, 15 etc). And then Apply Discount button is straight script of:

Set Field [ gUnitPrice; gTempPrice - Round( Div( gTempPrice * Filter( gDiscount; "0123456789" ); 100 ); 2 )

I have both gUnitPrice and gTempPrice displayed. Both fields are set number format 2 decimal, although gDiscount is text). Clicking the 10 inserts it into gDiscount. Then clicking the Apply Discount doesn't change gUnitPrice but clicking the other buttons changes it.

Is it possible to see your sample file so I can attempt to figure out what is different? Why would it work on every percentage but 10? crazy.gif

Otherwise, I'll have to change the calc again ... to .10, .15 etc and trying to make people do it right. I was hoping to keep it a straight percentage number. grin.gif

Well, this is weird ... clicking the 25 changes it to the IDENTICAL price of clicking 35!!! And the script parameters are right! Maybe it's in rounding and my number formatting!

The inconsistency of this is driving me nuts. I know I have it right - checked it over and over and over. Any help please, for me?

Posted

Well, I don't know math but I know something is wrong.

On 14.15 clicking 50% produces 7.15 and should be 7.05 right?!!

On 14.15 clicking 10% produces 13.15 and should be 12.73??

I've attached my test file. Please help me figure out why this isn't working. I'd be forever grateful to anyone to help me. I hate math. wink.gif

test.zip

Posted

Well, that works but people can type the period (which changes the result alot) or words or %, which is why I was using the filter. But I don't care at this point ... it works and that's enough.

I decided to give up on removing the bad characters but then remembered auto-enter and tried it. By unclicking Replace. The auto-enter removes the garbage and the script sets the field right! I changed the discount field to number also so I could remove the unnecessary GetAsNum. I think this was the calc Ugo was suggesting also. Why would it work in auto-enter and not the script? Puzzling to me.

I don't know how Queue got that filter calc to work in the script and would love to understand that, but for now I'm going to use this! I will actually be able to work on other things yet this weekend! THANK YOU!!! smile.gif

Posted

Thank you for the wonderful math link! I also needed to know how to figure a percent when I had two numbers but I was too embarrassed to ask ... after all the trouble with this and it probably being such a dumb question. blush.gif But this math link has the answer for that too -- 'Determining Percentage'!!

I remain unclear on why filter wouldn't work in my script; but I'm very tickled regardless. Thanks again for making my day. Oh, I can't wait to study this math link. grin.gif

Posted

Can you assist one more time Mr. Comment (or anyone that may read this)? The math link tells me what it should be ... sort of. But it tells me what the UnitPrice is to the RetailPrice (or WholesalePrice), NOT the amount of the discount applied. So I figure I have to then subtract this amount from 100, right? I tried many, many formulas.

Math link says:

Example: 68 is what percent of 87?

Divide the first number by the second (e.g. 68

Posted

I see what the problem was. Div was cutting off the fractional portion, but I was testing with whole numbers. Change Div to a regular division and it works.

Set Field [ gUnitPrice; gTempPrice - Round( gTempPrice * If( IsEmpty(gDisplayDiscount); Get(ScriptParameter); Filter( gDisplayDiscount; "0123456789" ) ) / 100; 2 ) ]

If you make sure nothing funky is entered in gDisplayDiscount, then you can use GetAsNumber instead of Filter.

The discount amount is the Round portion of the calculation.

Note that this calc returns $12.73 for a 10% discount on $14.15; the other one returns $12.74. So it depends whether you want 1.415 to round up to 1.42 (mine) or down to 1.41 (the other one).

The discount amount with the other calc is the original price - the calc, since the calc returns the discount price, and original price - discount price = discount amount.

Just so you know...

Posted

Thank you for the explanation, JT.

This last piece I'm stuck on ... I can't always use the Discount field to get the discount because sometimes they manually type the price in but want it to display what that discount percent is, for the customer. So I wanted the LineItem to just auto-enter replace what that discount is (the LineItems display in a portal below).

I can get the discount amount but not the discount percent (I have a field in LineItems called Savings).

Oh, so close to done. Why is my auto-enter calc (in my last post) wonky? I keep trying to make it work and it just won't. The LineItem auto-enters it and changes it if I change the price, but the percentage displayed is wrong. confused.gif

Please help me on this one. Then I promise I won't bother any of you about discounts EVER AGAIN! But I am still truly stuck on it.

Posted

I am not sure I follow your terminology, so let me put this in the general:

Discount = 1 - (SalePrice / RegularPrice)

If RegularPrice is 100, and SalePrice is 95, then Discount is 0.05.

Now, 0.05 is the same as 5/100, and 5/100 is the same as 5%.

In fact, the word "percent" comes from the Latin "per cent", i.e "for hundred".

If you want the result to be 5, instead of 0.05, then multiply by 100:

Discount = 100 - (SalePrice / RegularPrice * 100)

How you want to round this is up to you - this is not money.

Posted

Thank you Comment! Isn't that what my calc (in my last post) shows? The only difference is that I use Div instead of / and I round it.

Hmmm, maybe this is another issue like Queue indicates ... where Div doesn't handle the numbers right like / does. I will try changing my calc by removing the Round and the Div just to see what happens. Thank you!

IT WORKED!!!

If(ItemType = "Stock";

If(PriceBase = "Retail" ;

100 - (UnitPrice / RetailPrice * 100);

100 - (UnitPrice / WholesalePrice * 100)))

Oh! Hmmm, I don't think I like that Div function. It isn't very nice. I'm done!!!! Thank you all for hanging in there with me. I'd have quit long ago without your patient help on it. grin.gif YAY! I can go play!!

Posted

It's no mystery. Div automatically truncates the remainder while / includes the remainder (after the decimal.)

This topic is 7355 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.