How to access createdAt property from localstore object

Hi,
I am saving an object in the localstore where createdAt is made automatically by the db. I want to access the createdAt property of a particular object. It does not get retrieved with client.db.get(key). Can anyone help me figure out how to retrieve createdAt property from the localstore object?

Thanks

Hey @Aryan_Maloo

In Freshdesk’s key-value storage (localstore), the createdAt property is automatically generated by the database and is not directly accessible. However, you can store the createdAt timestamp as part of the object itself to retrieve it later. Here’s an example of how you can achieve this:

  1. When saving the object to the localstore, include the createdAt timestamp as a property within the object. For example:
const objectToSave = {
  data: "Your object data",
  createdAt: new Date().toISOString() // Include the timestamp
};

client.db.set(key, objectToSave);
  1. When retrieving the object from the localstore using client.db.get(key), you can access the createdAt property within the retrieved object:
const retrievedObject = client.db.get(key);

if (retrievedObject) {
  const createdAtTimestamp = retrievedObject.createdAt;
  // Use the createdAt timestamp as needed
} else {
  // Object not found
}

You can retrieve and use it as required.

1 Like

Thanks for the solution @Debjani.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.