How-To: Create GUID string using an external Node.js library
What Does This Article Cover?
- What is a GUID?
- How to set it up?
- Example
- Other Related Material
What is a GUID?
A GUID is a global unique identifier to is used to uniquely identify items across different systems. A GUID is almost impossible to duplicate. A GUID is a provides a simple way to create a unique key (identifier) between messages, objects, database records, etc.
How to set it up?
The setting of the GUI interval uses a third party npm library "js-guid". Downloading and installing Node.js and npm is covered here. Importing an npm library is covered here.
- Enable expression-imports on the Settings page.
- This will create a /appData/expression-imports folder
- Open a command window. Navigate to the expressions-imports folder and run the following command to install the npm package.
npm install js-guid
Example
The example first creates a function in the Functions windows on Intelligence Hub. The function will use the 'js-guid' library to generate a GUID. Once generated, the string of the GUID is return. Making this a global function in Intelligence Hub enables the function to be use multiple locations in your configuration.
Here is the expression...To copy, just cut and paste from within this window.
// this function calls the js-guid library to create a GUID and return it as a string
function generateStringGuid() {
let { Guid } = require('js-guid');
let guid = Guid.newGuid();
return guid.StringGuid;
}
Here is a screenshot of the function in the Function section of Intelligence Hub.
As an example of using this function, create a pipeline and add a Transform stage. Then, update the stage.setValue(event.value) to stage.setValue(generateStringGuid()). This will set the event.value equal to the return value of the generateStringGuid() global function. In the screenshot below, the results of the generateStringGuid() global function can be seen in debug mode (lower right-hand window).
Debug Mode is available in version 4.1 and greater.
Feel free to reach out to us if you have any issues or have any questions.