How do correctly create a uuid for a new database entry?

For anyone who finds this later, I figured out how to create a UUID using node (thanks to @sid for the excellent article here

  1. Install the UUID package by going to Terminal and typing npm install uuid

  2. Create these three folders in the root (extensions/server_connect/modules):

  3. Create a javascript module for the guid (I called mine guid_create.js) and add this code:

// JavaScript Document
const { v4: uuidv4 } = require('uuid');

exports.getValue = function (options, name) {
    const id = uuidv4();
    return id;
}
  1. Create the custom.json file with this code:
{
  type: 'guid_create',
  module : 'guid_create',
  action : 'getValue',
  groupTitle : 'My Modules',
  groupIcon : 'fas fa-lg fa-project-diagram comp-images',
  title : 'Create Guid',
  icon : 'fas fa-lg fa-file-alt comp-images',
  dataPickObject: true,
  properties : [
    {
      group: 'Create GUID',
      variables: [
        { name: 'name', optionName:'name', title:'Name', type:'text',required: true, defaultValue: ''},
        { name: 'output', optionName: 'output', title: 'Output', type: 'boolean', defaultValue: false }
      ]
    }
  ]
}

Sid’s article above does a good job of explaining the parameters for the hjson file so I won’t repeat that here.

  1. The new module should show up in server connect:

  2. Add the module to your server connect API:
    image

  3. Use your new guid variable in your insert statement!:

3 Likes