0

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
 

10 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    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:

     

    last('Item Image'.Image)

     

    If they are not linked then:

     

    let t := this

    let a := (select 'item image'  where 'Master Item ID' = t.'Master Item ID').image

    last(a)

     

    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.

    • Chapel_of_Praise
    • 2 yrs ago
    • Reported - view

    Thank you. I have a link setup but when I had tried to display the column with the image, it did not show. I assume your approach is to use a formula field with the 'last' code. right?  I appreciate it.

    • Fred
    • 2 yrs ago
    • Reported - view

    I just tried it in a formula field and just adding a column in table view and both did the same thing.

     

    Can you post your code?

    • Chapel_of_Praise
    • 2 yrs ago
    • Reported - view

    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?

     

    Thanks

    • Fred
    • 2 yrs ago
    • Reported - view

    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.

    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view

    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)

    Steven

      • Sean
      • 2 yrs ago
      • Reported - view

      RoSoft_Steven Have you gotten this to work in the Mac app with local images?

      • Ninox partner
      • RoSoft_Steven.1
      • 2 yrs ago
      • Reported - view

      Sean I didn't test this in the Mac app. I suppose it won't work as the shareFile() function is for cloud versions and not working in a local app. I have no solution for the native app's.😞🤔

      • UKenGB
      • 1 yr ago
      • Reported - view

      RoSoft_Steven Just tried using shareFile() in the Mac app and with a loop set up to share the appropriate images and then importFile() to the desired record, but it just blanks the target image field. 

      No problem entering the code to do it and the loop does run, but it just sets that  target image field to nothing, or null (clears out anything that was there).

    • Chapel_of_Praise
    • 2 yrs ago
    • Reported - view

    Thank you both for your help. I appreciate it!

Content aside

  • 1 yr agoLast active
  • 10Replies
  • 536Views
  • 3 Following