Image copy from Child Table to Parent Table
Here is the scenario I need help with:
Multiple people perform maintenance on Master Items. When they complete, they take a picture of the item and that image gets posted to an Item Image table. One Master Item may have 0 to Many Item Images.
To save time for personnel, when a new maintenance Item Image is captured, that latest image is copied back into a ‘Current Image’ field in the Master Item table (replacing any prior).
I want to place the code in a trigger. How do I structure the code to copy the image back to the right parent record?
let a := last(select ‘item image’)
help>> where ‘master item id’ = ‘item image’.’master item id’
‘Master Item’.’Current Image’ := a.Image
Is there a reason you need to copy the image from Item Image table to Master Item table? I'm guessing they are linked, so you can always just reference the latest image.
Something like this in a formula field on your Master Item table (assuming that your tables are linked and 'Master Item ID' is an actual reference field to Master Item table:
If they are not linked then:
let t := this
let a := (select 'item image' where 'Master Item ID' = t.'Master Item ID').image
Notice how much shorter the code is in the first one is? It is using the power of the reference field to gather data quickly. Ninox will take a record in Master Item then, automagically, only look at records that are linked in Item Image then pull the last one.
of course this assumes that the record with matching Master Item ID will always have the highest record (not Image) Id.
Good luck and let us know how it goes.
Fred, Thank you. Sorry for the delay but I was travelling. I got the code to work both ways you suggested.
A few other image questions.
1. If I set the image to "Handle File as Drawing" -- is there a way to set the ink color by default to BLUE via code?
2. When I capture an image or signature and I move records to a History Table, NINOX does not move the image file. Instead I get an "Image Failed to Load" message. Is it possible to move image copies?
I don't use images much so I don't have a deep understanding of how it works. So I don't know if question 1 can be done.
Question 2, Ninox doesn't copy images (at least on the MacOS app) very well. From my testing, I can't get it to copy drawings or signatures and when I try a pdf it says the pdf is there but can't show a thumbnail. When I try Save As it says failed.
If you are also encountering issues, one work around would be to create an image table that you never have to move the images from.
To move images from one table to another, you can use following scenario:
let i := shareFile(record(AnotherTable,1).Image); <<Source where the image is
ImagefieldInCurrentTable := importFile(this, i, "something.jpg") << Image field in the table where this code in a button is (note the "something.jpg", this is required but may use another file name and format such as .pdf or .png, depending on the type of source file it is)