Skip to main content

generateGuid / isEmptyGuid / EMPTY_GUID

Reference

Three exports for working with UUID / GUID values.

const { protrakUtils } = React.useContext(customWidgetContext);
const { generateGuid, isEmptyGuid, EMPTY_GUID } = protrakUtils;

generateGuid()

Generates a random UUID v4 string.

Returns: string — A UUID in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

const id = generateGuid();
// → "3f2504e0-4f89-11d3-9a0c-0305e82c3301"

EMPTY_GUID

A constant string representing an "empty" / null GUID.

Value: "00000000-0000-0000-0000-000000000000"


isEmptyGuid(guid)

Checks whether a GUID string is the empty GUID.

Parameters:

ParamTypeDescription
guidstringThe GUID string to check

Returns: booleantrue if the guid equals EMPTY_GUID, otherwise false.

isEmptyGuid(EMPTY_GUID); // → true
isEmptyGuid(generateGuid()); // → false
isEmptyGuid('abc-123'); // → false

Usage Example

function CreateNoteWidget(pageContext) {
const { protrakUtils, protrakComponents } =
React.useContext(customWidgetContext);
const { useProtrakApi, generateGuid } = protrakUtils;
const { Button, ButtonEnums } = protrakComponents;

const handleCreate = () => {
const tempId = generateGuid();
console.log('Creating note with temp ID:', tempId);
run({ tempId });
};

const { run } = useProtrakApi(
{ requestConfig: createNote, instanceId: pageContext.instanceId },
{ defer: true }
);

return (
<Button
text="Add Note"
appearance={ButtonEnums.Appearance.Primary}
onClick={handleCreate}
/>
);
}

const createNote = ({ instanceId }) => ({
endpoint: 'instances',
config: { method: 'POST', data: { typeName: 'Notes', name: 'New Note' } },
});