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.

Problem with button pointing to un-created invoice.

Featured Replies

OK, so I've run into a challenge with some scripting. Would appreciate some help here.

 

The context is as follows:

 

I have a layout set up for recording animal consult notes. 

 

At the bottom of the layout, are 2 buttons relevant to this issue. First is "Create New Invoice" & second is "View Existing Invoice"

(Visit Notes table and Invoice table are related via primary keys).

 

The first button works fine - generates a new invoice as intended. HOWEVER - I only want the "View Existing Invoice" button to bring up an invoice related to this animal  - only if it has been created yet

 

The Problem - At the moment however, if a new visit note has been made, but no invoice generated as yet, pressing the View Existing Invoice button brings up the previous dated invoice for that animal.

 

Instead I want it to show a dialogue to the effect of "No invoice has been created yet", and keep them on the visit notes layout so they can then tap the "Create New Invoice" button.

 

Scripts I have are below:

 

"Create New Invoice" button:

 

Show Custom Dialogue ["New invoice";"Confirm: Create  a NEW invoice for this visit?"]

Set Variable [$visit; Value:VisitNotes::_pk_VisitID]

Go To Layout ["Invoice"(Invoice)]

New Record/Request

Set Field [invoice::_fk_VisitID; $visit]

Go to Field [select/perform; Invoice::Date]

 

"View Invoice for Current Visit" button; (Blue text = unsure of syntax here)

 

Go To Layout ["Invoice)]

Go To related record [show only related records; Match found set; from table: "Invoice"; Using Layout: <Current layout>]

If [isEmpty (Invoice::_pk_InvoiceID)]

      Show Show Custom Dialogue ["No Invoice yet for this visit"]

      Then return them to the visit notes layout

Else

     Show the related invoice

 

I'm obviously doing something wrong in order for the "View Invoice" button to bring up a previous invoice where no invoice for the current visit exists. I figured the "Go To Related Record" script step should only work if a related record exists, not pull up the previous dated invoice (which is associated with it's own Visit Notes from the same date).

 

Help!

If the invoice has been created, and if it is directly related to the current consult note, you should be able to trap for invoice existance prior to using the go to related record command. Something like if related invoice ID is greater than 0 or if not is empty related invoice ID.

I have found using GTRR where no relation exists returns records. It is almost like the program throws up it's hands and says " Sure .... I don't know. You pick.", which appears to be the type of response you are getting now.

  • Author

Hi David,

 

Thanks for your comments,

 

On your first point - if an invoice has already been created, all works fine. However, as per your second point, it just throws up (in browse mode) all the invoices related to that animal, instead of telling me that one isn't related to that visit as yet.

 

Perhaps I should be trying the option of opening up the invoice layout using Find mode instead, and going there by way of a search for the related record - tho I suspect I will get the same outcome.

 

Frustrating that something which I thought would be a pretty simple true/false type scenario, doesn't seem to play out. It would appear that what I consider a logical step, isn't considered so by FM.

 

Grrrr!  :hmm:

 

Chris

 

 

If the invoice has been created, and if it is directly related to the current consult note, you should be able to trap for invoice existance prior to using the go to related record command. Something like if related invoice ID is greater than 0 or if not is empty related invoice ID.

I have found using GTRR where no relation exists returns records. It is almost like the program throws up it's hands and says " Sure .... I don't know. You pick.", which appears to be the type of response you are getting now.

Frustrating that something which I thought would be a pretty simple true/false type scenario, doesn't seem to play out. It would appear that what I consider a logical step, isn't considered so by FM.

 

It is, but you need to use your script steps in the correct order. Your error is that you first go to the other layout and then try to use the context (itself) as target for your GTRR. This doesn't work and simply leaves you at the last created record in Invoices. (No mysterious behaviour of the sort that Mr. McQueen hinted at.) 

 

Instead, do the check from your original layout. Change your script as follows:

 

If [ IsEmpty ( Invoice::_pk_InvoiceID ) ]

    Show Show Custom Dialogue [ "No Invoice yet for this visit" ]

    Exit Script

End If

Go To related record [ Show only related records; Match current record; from table: "Invoice"; Using Layout: ["Invoice) ]

# etc

 

You see that your Go to Layout step now is performed as component of the GTRR, but only if there is at least one related record.

 

Note that you could use the expression IsEmpty (Invoice::_pk_InvoiceID) within Conditional Formatting for your button to make it look dimmed, and then do without the message in your script.

Members is right. Script order is of importance....Which is pretty much what I thought I had said the first time through when I said trap for the existence of an invoice first.

  • Author

It is, but you need to use your script steps in the correct order. Your error is that you first go to the other layout and then try to use the context (itself) as target for your GTRR. This doesn't work and simply leaves you at the last created record in Invoices. (No mysterious behaviour of the sort that Mr. McQueen hinted at.) 

 

Instead, do the check from your original layout. Change your script as follows:

 

If [ IsEmpty ( Invoice::_pk_InvoiceID ) ]

    Show Show Custom Dialogue [ "No Invoice yet for this visit" ]

    Exit Script

End If

Go To related record [ Show only related records; Match current record; from table: "Invoice"; Using Layout: ["Invoice) ]

# etc

 

You see that your Go to Layout step now is performed as component of the GTRR, but only if there is at least one related record.

 

Note that you could use the expression IsEmpty (Invoice::_pk_InvoiceID) within Conditional Formatting for your button to make it look dimmed, and then do without the message in your script.

 

Ok, now that makes sense! After my last post, I was starting to head down a similar road (identify if the associated record exists or not, before I leave the current layout), but inexperience left me unsure of how to establish that (was looking at "Case" expression, amongst others - probably could be a number of ways to do this).

 

Haven't written your suggestion in just yet - but at least I now understand how to better order my 'steps'.

 

Will post back once I test the changed script.

 

Appreciate your input.

 

Thanks

Chris

  • Author

Members is right. Script order is of importance....Which is pretty much what I thought I had said the first time through when I said trap for the existence of an invoice first.

 

Thanks David,

 

When you wrote about trapping, you had preceded it with "If the invoice has already been created….." - which I took at face value, and my main concern was getting help for trapping when an invoice hadn't yet been created, that's all. 

 

Sorry I missed this reply earlier.

 

Cheers,

Chris

  • Author

It is, but you need to use your script steps in the correct order. Your error is that you first go to the other layout and then try to use the context (itself) as target for your GTRR. This doesn't work and simply leaves you at the last created record in Invoices. (No mysterious behaviour of the sort that Mr. McQueen hinted at.) 

 

Instead, do the check from your original layout. Change your script as follows:

 

If [ IsEmpty ( Invoice::_pk_InvoiceID ) ]

    Show Show Custom Dialogue [ "No Invoice yet for this visit" ]

    Exit Script

End If

Go To related record [ Show only related records; Match current record; from table: "Invoice"; Using Layout: ["Invoice) ]

# etc

 

You see that your Go to Layout step now is performed as component of the GTRR, but only if there is at least one related record.

 

Note that you could use the expression IsEmpty (Invoice::_pk_InvoiceID) within Conditional Formatting for your button to make it look dimmed, and then do without the message in your script.

 

 

Worked a treat! 

 

Thankyou

Chris

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.