Hexagon Geospatial
MENU

Developers Knowledge Base

GeoMedia Smart Client Workflow Manager provides tools for building and delivering highly-constrained, map-based workflows for the office or the field.
Showing results for 
Search instead for 
Do you mean 

Handle Files in GMSC (How To)

by Technical Evangelist on ‎09-01-2015 05:26 AM (2,820 Views)

Note: This how to works since GMSC13 + SP1 + engineering patches

 


Depending on your workflow or data model there are different ways how to handle files with GMSC:

One file per item is uploaded and the path to the file is stored in a column of the itemOne file per item is uploaded and is stored as binary in a column of the itemMultiple files per item may be uploaded and the paths to each file are stored in a separate tableMultiple files per item may be uploaded and the binaries of each file are stored in a separate table

 

How can each of these uses cases be handled using workflows?

Whenever files should be included in a Form, the form must contain a LINK FormFile.


One file per item is uploaded and the path to the file is stored in a column of the item

Add a FormFile to your form and set the datatype to be file. Furthermore an upload directory has to be defined.



<FormFile name="FilePath" datatype="file"uploaddir="C:\GMSC Warehouse\WorkflowFiles\{FORM.APPLICATIONNUMBER}" />

 

 

Every time the form is persisted, the file will be uploaded and the new path will be stored in the FilePath column of the item and if there is an existing entry, a download button shows up to download the file.

 

 

One file per item is uploaded and is stored as binary in a column of the item

 

Add a FormFile to your form and set the datatype to be binary. Whenever binary is used, the system needs to additional columns:

contenttypefield and filenamefield. GMSC fills the columns using the content type and file name of the uploaded file.

 

 

<FormFile name="FileData" datatype="binary" contenttypefield="ContentType" filenamefield="FileName" />

 

 

 

Every time the form is persisted, the file will be uploaded and stored as binary in the FileData column of the item and if there is an existing entry, a download button shows up to download the file using the file.

 

 

 

Multiple files per item may be uploaded and the paths to each file are stored in a separate table

 

To setup a workflow to support multiple file uploads an additional table is needed. This additional table may be filled using the SqlFileIteratorTrigger. The trigger may be executed after persisting the entry or may be called from a FormAction using IG.trigger. To upload the file itself a FormFile has to be added to your form.

 

FormSettings:

 

 

<Form name="BuildingExtensionsForm> 
 <FormTab name="AttachmentTab">  
  <FormGroup name="PathAttachments" >     
    <FormFile name="PathFiles" datatype="file" multiple="true" persisted="false" uploaddir="C:\GMSC Warehouse\WorkflowFiles\{FORM.APPLICATIONNUMBER}" >          
       <FormAction name="PathUpload" action="SCRIPT[IG.trigger({triggerNames:['FilePathUploadTrigger'], reloadFields:['PathUploadedFiles']}).done(function (result)
           IG.getItemById('PathFiles').reset()})]"/>
     </FormFile>     
    <FormTable name="PathUploadedFiles" idfield="Id" label="Uploaded Files" lov="SQL[SELECT Id, FileName FROM BE_ATTACHMENT WHERE Master_Id = {FORM.ID}]" persisted="false">
       <FormTableField name="FileName" label="Name" />           
       <FormAction name="PathDownloadFile" action="SCRIPT[IG.downloadFormFile({id:{ROW.Id},form:'PathFile', fieldName: 'FilePath', openFile:true})]"
          type="row" image="ig-icon-download" />           
       <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" />
   </FormTable> 
  </FormGroup>
 </FormTab>
</Form>
<Form name="PathFile" table="BE_ATTACHMENT" idfield="Id"> 
 <FormTab name="FormTab">   
  <FormGroup name="FormGroup">     
   <FormField name="Id" datatype="number" visible="hidden" required="false" />
      <FormFile name="FilePath" datatype="file" />   
  </FormGroup>  
 </FormTab>
</Form>

 

 


WorkflowSettings:

 

 

 

<WorkflowTrigger name="FilePathUploadTrigger" type="SqlFileIteratorTrigger" method="action" >
   <Param name="Sql" value="INSERT INTO BE_ATTACHMENT (Master_Id, FilePath, FileName) VALUES({FORM.ID}, {FilePath}, {FileName})"/>
   <Param name="Files" value="PathFiles" />
</WorkflowTrigger>
<WorkflowTrigger name="DeleteFilePathTrigger" type="SqlTrigger" method="action">
   <Param name="Sql" value="Delete From BE_ATTACHMENT Where ID = {REQUESTCONTEXT.fileId}"/>
</WorkflowTrigger>

 

 

In the FormSettings a FormFile is defined that lets the user select multiple files and the action uploads the files using a trigger. The FilePathUploadTrigger iterates over the files that have been uploaded and creates a new entry for each uploaded file.

In the FormTable the list of uploaded files is shown and for each row one action to download the file and one action to delete the file are defined.

In order to be able to download the file, another form is needed that represents the actual content of the attachment table. This is needed because the script action IG.downloadFormFile has to point to a file that represents the correct table. If this is not what you need, you can customize it using custom scripts and on the server side custom controllers.

Deleting the file can be done using a standard SqlTrigger.



Multiple files per item may be uploaded and the binaries of each file are stored in a separate table

 

Uploading multiple files at a time and store the files as binaries works quite similar. What is different is the structure of the table as the content type and file name have to be stored in separate columns again.

The definition could look like this:

 

FormSettings:

 

 

<Form name="BuildingExtensionsForm> 
 <FormTab name="AttachmentTab">
  <FormGroup name="BinaryAttachments" >
    <FormFile name="Files" datatype="binary" multiple="true" persisted="false" />
    <FormTable name="UploadedFiles" idfield="Id" label="Uploaded Files" lov="SQL[SELECT Id, FileName FROM BE_BINARYATTACHMENT WHERE Master_Id = {FORM.ID}]" persisted="false",
      selectionmode="multiple">
     <FormTableField name="FileName"  />
     <FormAction name="DownloadFile" action="SCRIPT[IG.downloadFormFile({id:{ROW.Id}, form:'BinaryFile', fieldName: 'FileData'})]" type="row" image="ig-icon-download" />
     <FormAction name="DeleteFile" label="Delete" action="SCRIPT[IG.trigger({triggerNames:['DeleteBinaryAttachmentsTrigger'], reloadFields:['UploadedFiles']})
      .done(function (result) {IG.getItemById('Files').reset()})]" />
   </FormTable>
  </FormGroup>
 </FormTab>
</Form>
<Form name="BinaryFile" table="BE_BINARYATTACHMENT" idfield="Id">
 <FormTab name="FormTab">
  <FormGroup name="FormGroup">
   <FormField name="Id" datatype="guidstring" visible="hidden" required="false" />
    <FormFile name="FileData" datatype="binary" contenttypefield="ContentType" filenamefield="FileName" />
  </FormGroup>
 </FormTab>
</Form>

 

 

WorkflowSettings:

 

 

<WorkflowTrigger name="BinaryFileUploadTrigger" type="SqlFileIteratorTrigger" method="after" condition="OBJECT[HasValueProvider.GetValue({FORM.Files})]">
 <Param name="Sql" value="INSERT INTO BE_BINARYATTACHMENT (Master_Id, FileData, FileName, ContentType) VALUES ({FORM.ID}, {FileData}, {FileName}, {ContentType})"/>
 <Param name="Files" value="Files" />
</WorkflowTrigger>
<WorkflowTrigger name="DeleteBinaryAttachmentsTrigger" type="SqlIteratorTrigger" method="action">
 <Param name="Sql" value="Delete From BE_BINARYATTACHMENT Where ID = {FORM.UploadedFiles}"/>
</WorkflowTrigger>


It works like the path sample just with different ways to upload and delete the files. In this sample the trigger will be executed after persisting the actual entry instead of calling the trigger using an action. To delete the files the user has to select the entries of the FormTable and execute the action that calls the DeleteBinaryAttachmentsTrigger. The trigger iterates over the selected items and deletes them. To download the files a separate form is needed again.

 

The complete sample can be downloaded here:

http://smartclient.intergraph.at/downloads/Workflows_FileSample.zip

 

The zip file includes the ddl statements to create the tables (just for SqlServer). It works the same way in Oracle but take care to adopt the statements and use a sequence where autonumber has been defined in SqlServer.

Overview
Contributors