SSD Assignment Audit Data storing issue

When i try to store audit data it show this error

2 Likes

Hi @mohammedrimshan ,

Can you show the mappings on the node where you are trying to store the audit data.

bh.local = bh.local || {};

try {
const payload = bh.input || {};
bh.local.auditData = {
action: payload.action || “UNKNOWN”,
entity: payload.entity || “N/A”,
entityId: payload.entityId || null,
user: payload.user || “system”,
timestamp: payload.timestamp || new Date(),
status: payload.status || “FAILED”,
details: payload.details || {}
};

console.log("Audit data ready:", bh.local.auditData);

} catch (err) {
bh.local = bh.local || {};
bh.local.error = err;
console.error(“Audit error:”, err);
throw err;
}

this is inside the script node

then when i creating the book i passed auditPayload

bh.local = bh.local || {};

bh.input.auditPayload = {
action: “CREATE_BOOK”,
entity: “Book”,
entityId: bh.local.result.book?._id || null,
user: bh.input?.user || “system”,
timestamp: new Date(),
status: bh.local.result.status === “created” ? “SUCCESS” : “EXISTS”,
details: {
isbn: bh.local.result.book?.isbn,
title: bh.local.result.book?.title,
author: bh.local.result.book?.author,
publishedYear: bh.local.result.book?.publishedYear
}
};

console.log(“Audit payload (nested):”, bh.input.auditPayload);

// Flatten payload to top-level bh.input
bh.input = { …bh.input.auditPayload };
console.log(“Flattened audit payload:”, bh.input);

@mohammedrimshan,

Are you only setting the error on the below code only ??

bh.local = bh.local || {};
bh.local.error = err;

yes , is there any change to make in here?

Hi @mohammedrimshan,

The code you provided seems fine, are you still getting the error??