How to display a drawing/image with different backgrounds in an external MariaDB database record?

I am currently trying to create two columns in a MariaDB table to hold two drawings that the app user can annotate and associate with each row, but I'm having trouble getting the drawings to use a template image that changes based on another column - attempting to set a dynamic background/default value results in the image field displaying an error 404 icon.
The MariaDB holds testing records for computers and is not something I can easily import/integrate into an AppSheet database. I would prefer to try and keep the drawings in the same table as the relevant data and store the information in the MariaDB directly. Ideally, what I'd like to do is:

  1. User looks up a record in the MariaDB table
  2. User opens a form to update and add information to that record, including annotating a template drawing
  3. The drawing uses the value of column [Chassis] in the MariaDB table to display a specific template before the user begins annotating
  4. The new information from the form is then added/updated to the existing MariaDB record, which can then be displayed in the record's Details view in the app

I am specifically having trouble with step 3 - I have no issues with displaying and saving a blank drawing with annotations, but trying to display a template from the beginning results in the drawing displaying a 404 error.

GreenLee_0-1708029943178.png

From what I can tell, what AppSheet stores in an image/drawing column is simply a text/string that refers to the image's relative filepath in AppSheet, so that is what I set the column type's in MariaDB to. I can hardcode that filepath as the default value on the MariaDB side to display one specific template, but I want to dynamically display different templates based on the value of column "Chassis" in the same table (eg. show different templates for laptops and desktops).

 


How can I set up the app so that the appropriate template will be displayed without errors? I used "=LOOKUP([Chassis], {template table}, {template name}, {image})" as the default value in another app to display dynamic templates without issue, but that was when working with only AppSheet databases and not an external database - here it only shows a blank drawing. I tried to set the same =LOOKUP function as the default value on MariaDB's side, but that causes the error shown above for ConditionDrawing1. ConditionDrawing2 is a blank drawing I saved as a test, and the entry for it in MariaDB is the drawing's relative filepath as a text string.

Is there a way I can configure this kind of dynamic template functionality in AppSheet with an external database? Do I need to reference the image in a different way in order to display it?

Solved Solved
0 3 149
1 ACCEPTED SOLUTION

For future reference, I managed to solve this by creating a trigger in the database table itself. The issue seems to be that because the record already exists, AppSheet won't use the default value formula to calculate an empty column, since that column has already been "set" as empty/null by the original database. Like I said in a previous comment, if the record was being created in AppSheet as a brand new row, then I could use a default value formula to calculate the template/background image without issue (eg. using the LOOKUP function I referenced).

Since I already knew the template image's values (a text filepath in "template table"), I simply rewrote the LOOKUP AppSheet function as a trigger in the MariaDB table that runs before insertion, reads and compares the record's Chassis column in an IF-ELSEIF statement, then sets the ConditionDrawing1/2 values of that row to the appropriate text filepaths that match the relevant template images. Then, when a user edits the drawing in a form, AppSheet will automatically save it as a new image and change the column value appropriately (which saves the template image from being overwritten, which was my biggest concern).

There's probably a prettier/more efficient way to do this, but for now this appears to be working for my needs.

View solution in original post

3 REPLIES 3

Please try to use first the proper format as.. 

LOOKUP([_THISROW].[Chassis],"template table", "template name", "image")

Unfortunately doesn't seem to work, still have the same problem. I think the issue lies in the fact that I'm trying to set a default value of a column in a record that already exists - because MariaDB has already defined it as NULL when first created, AppSheet doesn't apply the default value formula and instead just respects the original entry. Is it possible to get around this somehow, or will I need to manually configure some triggers on the database side?

I tested and found that if I were to create a brand new record for the external database through AppSheet, the template image would be displayed correctly based on the [Chassis] value using the above formula - but that's not an option for my use case since I only want to allow the user to update existing records.

For future reference, I managed to solve this by creating a trigger in the database table itself. The issue seems to be that because the record already exists, AppSheet won't use the default value formula to calculate an empty column, since that column has already been "set" as empty/null by the original database. Like I said in a previous comment, if the record was being created in AppSheet as a brand new row, then I could use a default value formula to calculate the template/background image without issue (eg. using the LOOKUP function I referenced).

Since I already knew the template image's values (a text filepath in "template table"), I simply rewrote the LOOKUP AppSheet function as a trigger in the MariaDB table that runs before insertion, reads and compares the record's Chassis column in an IF-ELSEIF statement, then sets the ConditionDrawing1/2 values of that row to the appropriate text filepaths that match the relevant template images. Then, when a user edits the drawing in a form, AppSheet will automatically save it as a new image and change the column value appropriately (which saves the template image from being overwritten, which was my biggest concern).

There's probably a prettier/more efficient way to do this, but for now this appears to be working for my needs.

Top Labels in this Space