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

Hi everyone,

I have a parent (Site), child (Inspections) and grand-child (Parts) relationship.  I have a field in Site and a field in Parts which have both inherited the same checkbox value list (file with sample data attached)

What I need:

1)  consolidate only a single set in all items into Site::fieldList1 for the parent.
2)  many of the values in both Site and Parts have spaces before or (possibly) after the value
3)  If there is more than a single value in the result in Site::fieldList1 and one of the values is 'none', I need the 'none' dropped

I considered recursive custom function, trimming the spaces first and then using ValueListItems() or using script to loop.  As I ponder my options, I would sure appreciate any high-level ideas of the best approach.  Thank you!

CompareLists.fp7

BTW, this is for a one-time cleanup and data migration of multiple individual files ( cities ).

I also do not want to add calculations to the file so I suppose that limits me to script although a custom function to assist script would be fine.

Edited by LaRetta
added word 'checkbox'

  • Author

What I would probably do is start at the Parts table and loop them, trimming first, testing if the value is in Site and then setting the Site.  But of course I'll have to trim the Site record as well.  It all feels a bit twisted.

43 minutes ago, LaRetta said:

I also do not want to add calculations to the file

Would you add a value list?

 

Edited by comment

  • Author

The new file will have a valueListItem table related to a valueList table eventually but it currently has the bogus value list with beginning spaces and I plan to clean that up so yes, it does.  :-)

I also believe I'm wrong about possible trailing spaces.  As for leading spaces, some of the files were corrected with the leading spaces and some not.  The value list with spaces is included in this sample file and it is in the master I am working on.

Edited by LaRetta

I am afraid that went over my head...

Anyway, I suggest you start by finding the Site records that have anything in the fieldList1 field OR in the Parts::fieldList2 field.

Then populate the target field (in Sites) by replacing its contents with:

List ( fieldList1 ; List ( parts::fieldList2 ) )

Now you have to trim the values individually, and de-dupe the list in each record. For de-duping, you could use a value list in a self-join to the same record - but I guess for a one-time cleanup a looping script might be preferable.

  • Author

Ah, combine into parent first!  Understood and script it is.  Is there any reason that this can't be done, via script, within a variable instead of the field?

5 minutes ago, LaRetta said:

Is there any reason that this can't be done, via script, within a variable instead of the field?

No, it's purely a matter of preference. I went for a field, because I thought of using a value list for the de-duping - and the field must be there anyway to hold the final result.

  • Author

That was perfect, Michael.  Thank you so much!  

  • Author

I'm fussing over this.  It worked great and then I realized I needed to still remove the 'None' if more than a single value and I am plagued by trailing carriage returns.  In truth, I should be able to do this all within a single Set Field[] step instead of two but no matter what I try, I get trailing return.  The first Set Field[] works (although I had to apply a kludge to remove the trailing return) and the failure is in the second.  I can apply a kludge to the second Set Field[] as well, I guess, but can you suggest a cleaner approach?

# FIND RECORDS
Go to Layout [ “site” (site) ] 
Enter Find Mode [ ]
Set Field [ site::fieldList1; "*" ] 
New Record/Request
Set Field [ parts::fieldList2; "*" ] 
Set Error Capture [ On ] 
Perform Find [ ]
If [ not Get ( FoundCount ) ]
Exit Script [ ] 
End If

# COLLECT VALUE LIST VALUES ( this may be from a table when migration takes place )
Set Variable [ $valueList; Value:ValueListItems ( "" ; "OtherPermits" ) ]

# we are on first record
Loop
Set Field [ site::fieldList1; 

Let ( [
  allValues = List ( site::fieldList1 ; List ( parts::fieldList2 ) ) ; 
  expand = Substitute ( allValues ; "¶ " ; ¶ ) ; 
  values = Substitute ( TrimAll ( expand ; 0 ; 0 ) ; "  " ; ¶ ) ; 
  result = FilterValues ( $valueList ; values )
];
Left ( result ; Length ( result ) - 1 )
)]

If [ ValueCount ( site::fieldList1 ) > 1 and Position ( site::fieldList1 ; "None" ; 1 ; 1 ) ]
  Set Field [ site::fieldList1; Substitute ( ¶ & site::fieldList1 & ¶ ; "¶None¶" ; "" ) ] 
End If
Go to Record/Request/Page [ Next; Exit after last ] 
End Loop

If not, I'll just kludge and two-step this puppy.  :-)

BTW, I was incorrect in that all cites are using a value list identical to the one in the file I presented.  ALL have beginning spaces so that simplified my need.

Edited by LaRetta

Does the "OtherPermits" value list include all possible values you want to keep? You didn't mention this earlier. If true, then your task is much easier.

But I don't understand this part:

values = Substitute ( TrimAll ( expand ; 0 ; 0 ) ; " " ; ¶ ) ;

How can you do this, when you have legitimate values with space/s in them, e.g. "Air Quality"?
 

  • Author

"Does the "OtherPermits" value list include all possible values you want to keep? "

Yes.

There are two spaces there.  It doesn't look like it translated properly.

I've corrected the code.  I had to correct it several places when I pasted here and I missed one.  :-/

The rest of it appears correct.

Edited by LaRetta

I have another preliminary problem: why are there leading spaces in the "OtherPermits" value list?

  • Author

I have removed them.  Sorry, they should be removed in your file as well.

That's how the value list originally was served up and why the results included spaces.  It is now corrected in the master file.

Okay, so would this work for you, as the calculation for Set Field (or Replace Field Contents)?

Let ( [
valueList = ValueListItems ( "" ; "OtherPermits" ) ;
allValues = List ( site::fieldList1 ; List ( parts::fieldList2 ) ) ;
trim = TrimAll ( allValues ; 0 ; 0 ) ;
clean = Substitute ( trim ; [ " ¶" ; ¶ ] ; [ "¶ " ; ¶ ] ) ;
keep =  FilterValues ( valueList ; clean )
] ;
If (
ValueCount ( keep ) > 1 and not IsEmpty ( FilterValues ( "None" ; keep ) ) ;
Let ( remove = Substitute ( ¶ & keep ; "¶None¶" ; ¶ ) ; Middle ( remove ; 2 ; Length ( remove ) - 2 ) ) ;
Left ( keep ; Length ( keep ) - 1 )
)
)

Note: I have not tested this.

---
P.S. Since "None" will always be the first value, you could simplify this and just remove the first value if the test is true.

 

Edited by comment

  • Author

A few points:

  1. I hadn't considered searching for values in both tables before beginning.  That cut the task in half.
  2. I hadn't considered RFC since I rarely use it, but it is perfect here since this will be stand-alone files during migration process.
  3. I hadn't considered removing None from first value!
  4. I originally started to write this and tested it using TrimAll() (please see screenshot).  The results are no different than Trim() so we can use Trim() instead.

As you say, this was untested but it certainly works and it amazes me that you can put it together without testing!  

Regardless, I ran yours through 400+ records and it is perfect (no surprise).  Thank you so much for assisting me in learning better approaches and ways of thinking.  I really appreciate it!

TrimAll.png

Oh wait. :|  You used TrimAll() in case there were other spaces between.  Right?  My bad!  I shall use TrimAll()!!

Edited by LaRetta

I used TrimAll() in case you happen to have a value followed (or led) by two or more spaces. The Substitute() handles only one leading and one trailing space.

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.