Having Images as choices for a question

Having Images as choices for a question

Requirement

A form containing questions must have multiple choices in image format as answers for each question.  

Use Case

A brain-teaser application is built that has a Questions form, which lists all kinds of questions. A question has multiple options to choose from. For some questions the answers need to be chosen among images, so the options need to be images.
 
See how it works

Steps to follow

1.  Create the forms  with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Images
Images
Image
Image
Image
Question
Question
Add Notes
Notes
plain
Radio
What will replace the Question Mark?
What_will_replace_the_Question_Mark
 
We shall now add the options and the question as images to the Images form. The question will be an Image field and the answer will be to choose from a set of Image choices. Insert those records to the form.
 
2.  Next, let's learn how to get the uploaded images' URL to insert them to our form. We shall create a function to get the image's URL and devise a way to reconstruct them. Create a function named, getAllImages to get the image URLs.
Note: The files that you upload will be scanned for any virus. You will have to upload a different file if the uploaded file contains a virus.


3. Add the below code in the Deluge Editor:
  1. void getAllImages()
  2. {
  3.  for each image in Images[ID != null]
  4.  {
  5.   info image.Image;
  6. <Insert Snippet 1 >
  7. < Insert Snippet 2 >
  8.  }
  9. }
The Info Statement (Line no 5) prints the image URL as below: 

<img src = " https://creatorexport.zoho.com/sharedBy/appLinkName/viewLinkName/fieldName/image/ 1625047562073_Question.png" lowqual = " https://creatorexport.zoho.com/sharedBy/appLinkName/viewLinkName/fieldName/image/1625047562073_710" medqual = " https://creatorexport.zoho.com/sharedBy/appLinkName/viewLinkName/fieldName/image/1625047562073_710" downqual =
" https://creatorexport.zoho.com/sharedBy/appLinkName/viewLinkName/fieldName/image/1625047562073_Question.png" border = "0"></img>
The bold part of the text is the name of the uploaded file stored. We need to split that from the Image field value. Other methods are explained in the Points To Note .
 
Snippet 1:
Let's get the suffix of the /image/ until the first double quote (") (escaped with \ ), as shown underlined above:
  1. //Get the uploaded image's file name
  2. fileName = image.Image.getSuffix("/image/").getPrefix("\"");
  3. info fileName;
This info statement will print the name of the uploaded image file name as 1625047562073_Question.png
 
Snippet 2:
Next, let's construct the image URL:
  1. //Construct the image URL
  2. img = " https://creatorexport.zoho.com/file/" + zoho.appuri + "All_Images/" + image.ID + "/Image/image-download?filepath=/" + fileName;
  3. info img;
The above snippet will result in: " https://creatorexport.zoho.com/file" + /scopeName/appLinkName/ + reportLinkName + image.ID + "/Image/image-download?filepath=/" + fileName ;
Parameter
Value
Description
/scopeName/appLinkName/
zoho.appuri
This system variable gives the scope name and the application's link name as required in the URL
reportLinkName
All_Images/
The report link name of the Images form
image.ID
<19 digit record ID>
Record link ID of the needed image
fileName
1625047562073_Question.png
Name of the image uploaded as stored

4.  In the Questions form, click the Notes field, then click the Edit HTML icon.

5.  Insert the below code to display the question image:
  1. <div>
  2.     <div>
  3.         <img src = " <Paste the question URL from the function> ">
  4.         <br>
  5.     </div>
  6.     <div>
  7.         <br>
  8.     </div>
  9.     <style>
  10. //Make the question name look a bit bigger.
  11.         .zc-What_will_replace_the_Question_Mark-group .form-label span { font-size: 1.5rem }
  12.     </style>
  13. </div>
  14. <div>
  15.     <br>
  16. </div>

6. To show the options on the load of the Question form, let us create a workflow to execute during the load of the form.


7.  Click  Add New Action and add the below code in the Deluge Editor . These are the image URLs that were constructed in Step 4 .
  1. for each image in Images[ID != <QuestionID>]
  2. {
  3. fileName = image.Image.getSuffix("downqual = \"").getSuffix("image/").getPrefix("\"");
  4. img = "<img src=\" https://creatorexport.zoho.com/file/" + zoho.appuri + "All_Images/" + image.ID + "/Image/image-download?filepath=/" + fileName + "\"/>";
  5. input.What_will_replace_the_Question_Mark:ui.add(img);
  6. }

This will load the options as images for the What will replace the Question Mark? field.

See how it works

Points To Note

  1. In Step 4, we have found the name of the file using the index of /image/. We can also use downqual and lowqual, as shown below, to find the file name:
  1. //Using lowqual
  2. image.Image.getPrefix("lowqual = \"").getSuffix("image/").getprefix("\"");  
  3. //Using downqual
  4. image.Image.getSuffix("downqual = \"").getSuffix("image/").getPrefix("\"");