December 12, 201312 yr 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!
December 12, 201312 yr 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.
December 13, 201312 yr 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! 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.
December 13, 201312 yr 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.
December 14, 201312 yr 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.
December 14, 201312 yr 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
December 16, 201312 yr 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
December 17, 201312 yr 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