Skip 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.

Selecting the record I want

Featured Replies

  • Newbies

I'm attempting to create a calculated field that displays the last date a customer received maintenance. This is the calculation I'm using:

 

Case ( GetNthRecord ( Agreements::PM Type ; Agreements::Agreement count ) = "GPM" or "GPMA-FULL" or "GPMA-HEAT" ; GetAsDate ( GetNthRecord ( Agreements::six mo date ; Agreements::Agreement count ) ) ; GetNthRecord ( Agreements::PM Type ; Agreements::Agreement count ) = "SPM" or "BPM" or "STU" or "BTU" ; GetAsDate (GetNthRecord ( Agreements::Purchase Date ; Agreements::Agreement count )  ) ; "NO PM" )

 

I thought that this would work, grabbing the last created record, but I am realizing that some of these agreements were inputted out of order, therefore causing my calculation to work incorrectly. What I'm hoping for is a way to sort records by date and grab the most recent one. Any help would be greatly appreciated.

Use a relationship that is sorted by agreement type – in a way that Maintenance records come first (e.g. by using Value List) – then by date descending.

 

Look at the first Agreement record via that relationship; if it's a Maintenance type, that's your date; if it isn't, there are no Maintenance agreements for that customer.

 

Alternatively, you could use ExecuteSQL, like 

ExecuteSQL ( "
  SELECT MAX ( theDate ) 
  FROM Agreements 
  WHERE 
    customerID_fk = ? AND 
    agreementType IN ('GPM','GPMA-FULL','GPMA-HEAT') 
  " ; "" ; "" ; Customer::customerID_pk 
)

Be aware that a date returned by SQL needs to be parsed into a date in FM format.

 

As to your calculation: though syntactically valid, e.g. this GetNthRecord ( Agreements::PM Type ; Agreements::Agreement count ) = "SPM" or "BPM" or "STU" or "BTU" doesn't do what you probably expect; and there is no need to use GetAsDate ( aDateField ) …

 

… and in general, the calculation is just plain confusing: you should use proper formatting to make it better understandable – which would also allow you to see faster if it makes sense, or not, as it were.

  • Author
  • Newbies

Ok, That makes sense because they're related to Job Codes, which are sorted by creation date.

I know nothing about SQL are there any good primers you could recommend?

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

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.