Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

I looked but was not able to find it, if it is out there would someone point me to it or tell me how would this be accomplished?

I would like a field that would count/show if a button was pressed?

For example:

Print button for invoices.

When it is pressed it would print the invoice and insert words "printed 1" into the field next to it.

If it is pressed again it would insert "Printed 2".

I am looking to writing a script that once the button is pressed:

Prints the invoice

Checks to see if the field next to it has anything inside

If it does not then it inserts Printed 1

If it has Printed # inside already it would increase the value

Am I going in the right direction here? If I am I could use a hint as to how to get the script to recognize what information, if any, is already inside the field and increase it accordingly.

Thanks.,

You could have a number field called Printed. Each time it is printed (via script), your print script would add this script step at the end:

Set Field [ Printed ; Printed + 1 ]

LaRetta :wink2:

  • Author

Thanks for pointing me in the right direction. I got it with "insert calculated result"

As calc I put:

"Printed" & Test2::Print_count + 1

It is better to use Set Field [] rather than Insert Calculated Result [ ].

With Insert Calculated Result [ ] , the field must ALWAYS be on the layout; Set Field [ ] has no such limitation. And yes, your Printed field can be text. But, for it to also include the words 'printed' then you can't append to it unless you combine text function with mathematics. Try:

Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1

Truly, it is better the leave the word 'Printed' out of the field and just have it be the text label.

LaRetta

  • Author

Thanks., will use set field instead then. Did not know of the limitations as you mentioned - I am still quite new to FM and I pretty much know that the stuff I make probably has a better way of being done then how I made it however I am pretty much self-learn type of a person.

I will also set printed as a separate field then as I want the word not being visible until the invoice is printed at least once. It will trigger the first time the button is pressed.

By the way how would I be able to detect if someone canceled the print dialog and then have the script clear the fields if it was canceled?

Immediately after your Print script step, add

Set Variable[$print; Get(LastError)]

If the user cancels printing, Get(lastError) returns a 1, if printing is fine, a 0.

You then add an error trap:

If[$print]

#What result you want if printing isn't successful

Else

#what you want if printing is sucessful

End If

I will also set printed as a separate field then as I want the word not being visible until the invoice is printed at least once. It will trigger the first time the button is pressed.

There is no need to use a separate field for the word printed. Either place the field name on the form or leave the calculation as I had it. The word 'printed' will not appear in the field until it is printed at least once anyway. It would be a shame to waste another field just to hold one word that you set via script (which would also need to then be cleared).

By the way how would I be able to detect if someone canceled the print dialog and then have the script clear the fields if it was canceled?

Again, no need to clear the field; simply don't set the number (or increment it up) until after the print is successful. And I see no reason to use a variable. Here's one way it can work:

Set Error Capture [ On ]

Print [ ]

If [ Get ( LastError ) ]

Exit Script

Else

Set Field [ Printed ; Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1 ]

End If

LaRetta :wink2:

Case ( IsEmpty ( yourTable::Printed ) ; "Printed " ) & LeftWords ( yourTable::Printed ; 1 ) & " " & RightWords ( yourTable::Printed ; 1 ) + 1

If it were me, I'd put in a list of timestamps (or users and timestamps) to keep a log of who printed when. But to get the result above, you could do:

Case ( IsEmpty ( PrintLog ) ; "Printed 1" ; SerialIncrement ( PrintLog ; 1 ) )

or just:

SerialIncrement ( "Printed 1" ; PrintLog )

Interesting Michael, this is another one of those functions i've never really seen used before..

Cheers.

Now this is very cool, Michael! I shall steal it! I can already see thousands of great uses for it. :wink2:

BTW, I considered mentioning a log (or even table) but I got lazy. Thanks for covering it.

Edited by Guest

or just:

SerialIncrement ( "Printed 1" ; PrintLog )

Stolen ! :P

( stored )

  • Author

WoW, thanks, a lot of good information here, will right that down for future reference and learn from it.

Thanks.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.