×

Please give details of the problem

Skip to content

Server-Side Javascript ES6 API Reference

RMPFile

Methods for the Management of Files

Create File

Create a new file. Works only for uploaded files

Syntax :

  • RMPFile.create(name, content);
  • RMPFile.create(name, content, options);

Parameters :

Name Type Description
name String Name of the file
content String The data to be added into the file.
options (optional) Map Optional parameters

The "options" map is currently limited to:

Name Type Description
charset String Character-set e.g "UTF-8"

Returns : Identifier of the created file.

Type : String

Call Example :

  
    <@script env="js">
      var f = RMPFile.create('test2.txt', 'abcdef');
      RMPData.setOutput(f);
    </@script>
   

Delete File

Delete an existing file. Works only for uploaded files.

Syntax : RMPFile.delete(fileID);

Parameters :

Name Type Description
fileID String Identifier of the file to be deleted.

Returns : The result of the delete operation (true, false)

Type : Boolean

Call Example :

  
    <@script env="js">
      var f = "54fedbb0-b9ae-11ed-b944-d68b202471ff";
      RMPFile.delete(f);
    </@script>
   

File Content

Read the content of a file.

Note: Please make sure that you don't exceed the maximum memory limit when using the function.

Syntax :

  • RMPFile.getContent(fileID);
  • RMPFile.getContent(fileID, encoding);
  • RMPFile.getContent(fileID, encoding, charset);

Parameters :

Name Type Description
fileID String Identifier of the file.
encoding (optional) String "BASE64" or "NONE"
charset (optional) String Character-set e.g "UTF-8"

Returns : The Content of the file

Type : String

Call Example :

  
    <@script env="js">
      var f = "3146acd0-b0e8-11ed-ac99-ea641a55cdec";
      var content = RMPFile.getContent(f);
      RMPData.setOutput(content);
    </@script>
   

Save Content

Overwrite an existing file. Works only for uploaded files.

Syntax :

  • RMPFile.save(fileId, content);
  • RMPFile.save(fileId, content, options); * Parameters :
Name Type Description
fileID String Identifier of the file to be overridden.
content String New content of the file.
options (optional) Map Optional parameters

The "options" map is currently limited to:

Name Type Description
encoding String file encoding - BASE64, NONE
charset String Character-set e.g "UTF-8"

Returns : Identifier of the file

Type : String

Call Example :

  
    <@script env="js">
      var f = RMPFile.create('text.txt', 'abcdef');
      RMPFile.save(f, 'hirsch');
      RMPData.setOutput(f);
    </@script>
   

Append File

Append data to an existing file. Works only for uploaded files.

Syntax :

  • RMPFile.append(fileID, content);
  • RMPFile.append(fileID, content, charset);
  • Parameters :
Name Type Description
fileID String Identifier of the file to be appended. A new file is created if ‘fileID’ is empty.
content String The data to be added into the file.
charset (optional) String Character-set e.g. "UTF-8"

Returns : Identifier of the appended file.

Type : String

Call Example :

  
    <@script env="js">
      RMPFile.append("3146acd0-b0e8-11ed-ac99-ea641a55cdec", 'defghi');
    </@script>
   

File Replace

Replace the occurrences of a string in a file and save it. Works only for uploaded files.

Syntax :

  • RMPFile.replaceInFile(fileID, oldString, replacement);
  • RMPFile.replaceInFile(fileID, oldString, replacement, options);
  • Parameters :
Name Type Description
fileID String Identifier of the file.
oldString String The data to be replaced
replacement String The data to be inserted or replaced with
options (optional) Map Optional parameters

The "options" map is currently limited to:

Name Type Description
flag String 'f'=first occurence only, 'r'=all
algorithm String file encoding - BASE64, SHA1, SHA-256, MD5, NONE
charset String Character-set e.g "UTF-8"

Returns : File Identifier.

Type : String

Call Example :

  
    <@script env="js">
      var f = "3146acd0-b0e8-11ed-ac99-ea641a55cdec";
      RMPFile.replaceInFile(f, 'abc', 'efg');
    </@script>
   

File Size

Get the size in KBytes of a file on the platform.

Syntax : RMPFile.getSize(fileID);

Parameters :

Name Type Description
fileID String Identifier of the file.

Returns : Size of the File in KB (KiloBytes) along with File description.

Type : Map

  
    {"customer", {Long},
     "id", "{String}", 
     "name", "{String}", 
     "size", {Long},
     "type", "{type}", 
     "visibility", "{String}", 
     "created", "{UTCData}",
     "updated", "{UTCData}",
     "right": {map}, --- optional
     "engine": "{String}" --- optional
   }
   

Call Example :

  
    <@script env="js">
      var f = "3146acd0-b0e8-11ed-ac99-ea641a55cdec";
      var fileSize = RMPFile.getSize(f);
      RMPData.setOutput(fileSize);
    </@script>
   

Index Of

Find the index of the first occurrence of a string in a file.

Syntax :

  • RMPFile.indexOf(fileId, substring);
  • RMPFile.indexOf(fileId, substring, options);

Parameters :

Name Type Description
fileID String Identifier of the file to be searched upon.
substring String Text to be matched with the file content
options (optional) Map Optional parameters

The "options" map is currently limited to:

Name Type Description
from Integer start index
algorithm String file encoding - BASE64, NONE
charset String Character-set e.g "UTF-8"

Returns : Index position of the given string.

Type : Integer

Call Example :

  
    <@script env="js">
      var f = "3146acd0-b0e8-11ed-ac99-ea641a55cdec";
      var idx = RMPFile.indexOf(f, 'ab');
      RMPData.setOutput(idx);
    </@script>
   

Last Index Of

Find the last occurrence of a string in a file.

Syntax : RMPFile.lastIndexOf(fileId, substring);

Parameters :

Name Type Description
fileID String Identifier of the file to be read.
substring String String to be searched in the file content.
options (optional) Map Optional parameters

The "options" map is currently limited to:

Name Type Description
from Integer start index
algorithm String file encoding - BASE64, NONE
charset String Character-set e.g "UTF-8"

Returns : Index of the first occurrence or -1 if nothing is found.

Type : Integer

Call Example :

  
    <@script env="js">
      var f = "c0a25fde-63a7-482e-bdcb-49c1959126aa";
      var idx = RMPFile.lastIndexOf(f, 'ab');
      RMPData.setOutput(idx);
    </@script>
   

Get File Description

Get the metadata describing a file on the platform.

Syntax : getDescription(fileID);

Parameters :

Name Type Description
fileID String Identifier of the file.

Returns : The description of a file.

Type : JSON Object

Call Example :

  
    <@script env="js">
      var f = "3146acd0-b0e8-11ed-ac99-ea641a55cdec";
      var description = RMPFile.getDescription(f);
      RMPData.setOutput(description);
    </@script>
   

Save Description

Modify the metadata describing a file on the platform.

Syntax : RMPFile.saveDescription(fileId, metadata);

Parameters :

Name Type Description
fileID String ID of the file to be modified.
metadata Map New metadata of the file.

The "metadata" map is currently limited to:

Name Type Description
name String file name
size Long file size (should normally not be changed)
type String file type
visibility String PRIVATE, PUBLIC

Returns : New metadata of the file.

Type : Map

Call Example :

  
    <@script env="js">
      var f = RMPFile.create('text.txt', 'abcdef');
      var payload = {'desc' : 'file desc'};
      var description = RMPFile.saveDescription(f, payload);
      RMPData.setOutput(description);
    </@script>
   

UNZIP

Unzip a file, and create a new file with the unzipped data. Works only for uploaded files.

Syntax : RMPFile.unzip(fileID);

Parameters :

Name Type Description
fileID String Identifier of the file to be unzipped.

Returns : UNZIP File Identifier.

Type : Array of Strings (file IDs)

Call Example :

  
    <@script env="js">
      var fileId = "bd98d36e-fae7-40e6-98b6-9c115305110f";  
      var unzipFileId = RMPFile.unzip(fileId);  
      RMPData.setOutput(unzipFileId);   
    </@script>
   

ZIP

Zip a file, and create a new file with the zipped data. Works only for uploaded files.

Syntax : RMPFile.zip(name, fileIDs);

Parameters :

Name Type Description
name String Name for the ZIP file to be created
fileIDs List (String) Identifier of the files to be zipped.

Returns : ZIP File Identifier

Type : String

Call Example :

  
    <@script env="js">
      var fileId = "54fedbb0-b9ae-11ed-b944-d68b202471ff";
      var zipFileId = RMPFile.zip('test.zip', [fileId]);
      RMPData.setOutput(zipFileId);
    </@script>
   

Read Excel Spreadsheet

Read cells from an Excel worksheet.

Note: Works for XLSX format of Excel files only

Syntax : RMPFile.readExcelSpreadsheet(fileId, sheetName)

Parameters :

Name Type Description
fileID String Identifier of the Excel file uploaded on the platform.
sheetName String Worksheet descriptor listing the cells to be read.

Returns : Content of the spreadsheet

Type : Two-dimensional array

Call Example :

  
    <@script env="js">
      var sheet = RMPFile.readExcelSpreadsheet('54cfc512-2307-494c-a5f7-2e262c3e1add', 'Sheet1');
      sheet.forEach(function (item) {
        item.forEach( function (item) {
          console.log(item);
        });
      });
      RMPData.setOutput(sheet);
    </@script>