M.App Enterprise Discussions

Discuss topics with other M.App Enterprise Product pioneers and experts to get the most out of it.
Showing results for 
Search instead for 
Do you mean 
Posts: 24
Registered: ‎05-11-2018
Accepted Solution

Viewing an image from the database



I am viewing an image from the database and I can do this with the following:


<Form name="ImageForm" editable="true" idfield="id" table="WMS_STREET_IMAGES">
    <FormTab name="NewTabPage1" editable="true" visible="true">
      <FormGroup name="imagedetail" editable="true" visible="true">
        <FormField name="id" editable="true" visible="hidden" datatype="string" defaultvaluemode="onload" required="true" persisted="true" saveinsession="false" type="textfield" override="false" />
        <FormFile name="image" editable="true" visible="true" datatype="binary" defaultvaluemode="onload" persisted="true" override="false" multiple="false" filenamefield="entity_id" contenttypefield="image_mimetype" useuniquename="true" />

And I am able to open the images with the following:


<FormAction name="Photo" editable="true" visible="true" action="SCRIPT[SC.Media.downloadAndOpen(IG.createFieldDownloadUrl({id:{ROW.id}, form:'ImageForm', fieldName: 'image', openFile:true}))]" type="row" />

However when I open the image again I get a Java.Lang.NullPointerException


It looks likes, because the image is in my Local\Temp folder, the action will not overwrite the file in my temp folder?


Is there an option in IG.createFieldDownloadUrl() to force a file overwrite?


If I manually delete the created file form the AppData\Local\Temp folder I can perform the action with no error.


Thank you


Technical Evangelist
Posts: 660
Registered: ‎11-12-2015

Re: Viewing an image from the database

Hi Ciaran,


With these type of actions I will also include the action to delete the path by calling a trigger so that the manual delete is not necessary.


Here is an example:




<FormAction name="DeletePath"
             action="SCRIPT[IG.trigger({triggerNames:['DeleteFilePathTrigger'],urlParams:{fileId:{ROW.Id}}, reloadFields:['PathUploadedFiles']}).done(function (result) {IG.getItemById('PathFiles').reset()})]"
             type="row" image="ig-icon-delete" />


<WorkflowTrigger name="DeleteFilePathTrigger" type="SqlTrigger" method="action">
          <Param name="Sql" value="Delete From BUILDING_ATTACHMENT Where ID = {REQUESTCONTEXT.fileId}"/>

I am not aware of a way to overwrite the existing file.


Posts: 24
Registered: ‎05-11-2018

Re: Viewing an image from the database

Hi Stephen,


Thank you for the response.


The trigger you sent me is deleting the photo from the database. I don’t want to do this. I want to be able to remove the photo from the temp folder on the users machine but not from the database.


Using the SC.Media.downloadAndOpen script does not seem to allow overwrite or creation of a new image (if there is an existing image with the same name).


The following script works (creates a new image in the temp folder if it already exists) but it does involve an extra 2 clicks from the user:


action="SCRIPT[SC.Media.showFile(IG.createFieldDownloadUrl({id:{ROW.id}, form:'ImageForm', fieldName: 'image'}))]"



Technical Evangelist
Posts: 660
Registered: ‎11-12-2015

Re: Viewing an image from the database

Thanks for sharing your solution Ciaran.

Of course you will know your end desire better than I and there will be even multiple ways one can accomplish this task.