How to compress a string in UI Builder

Hello,

I can’t find any documentation or support topics to help with this.

Is is possible to compress a string using UI Builder to save this in the database? Currently I get a string object that is larger than the 21000 symbol limit for a text entry into the DB, I would like to compress this to save it and then be able to decompress when I need to use it again in the future. Is this possible using UI Builder?

Hi @Luc_Zentar

Unfortunately, we don’t have a built-in block that can implement this task. You can search for a solution to this task in JavaScript on the internet and then use the Custom Code block to execute that code.

Regards,
Viktor

I’ve searched and can’t find any solutions that don’t need to import libraries, which I don’t think I can do with Backendless UI Builder. Any further help or pointers in the right direction would be much appreciated.

Hi @Luc_Zentar

You can try the following options to achieve the required:

  1. Try plugging in the required library using the Custom Code block, that is one of the options.

  2. Or, you can try reducing spaces using the expressions, like this one as example:

const minifyString = string => string.replace(/\s+/g, ё ё).trim();

Regards,
Marina

Thank you Marina, I have tried the first option and this is the code I’m using:

const LZString = require(‘lz-string’);

const compressString = (str) => {
return LZString.compressToUTF16(str);
}

// Use the compressString function
let myData = receiptData;
let compressedData = compressString(myData);

// Return the compressed data
return compressedData;

But I get the error Uncaught (in promise) Error: Module name “lz-string” has not been loaded yet for context: _. Use require()

The problem is in import.

You could copy minimized code from lz-string repo and use it in your custom code function.