Very new to JSON, need some help

Hey Everyone, I’m crazy new to JSON. IT 20 years, and was just thrown into a this is our new ticket system and it’s JSON based for custom jobs so learn it lol. I’m working to create a job that will automate a message if a ticket hasn’t been touched in 7, 14, 30 days and then close. But It’s not working exactly right, it seems stuck on step 2. We dont’ have a json person and I’m taking some online classes to start learning but this is what I’ve been able to come up with

There’s already a separate rule that if they comment it changes the state from Validation or Client Acceptance back to under review so you’ll see below where it’s looking for the previous incase it has been reset by that rule

So I have 3 rules based on age. And whether or not the end user has responded.

const rules = [ // last rule will close the ticket
{
limit: 7,
reminder: “We continue to look for your feedback and want to make sure we have assisted in providing you what you need. We have not heard from you for 7 days. If we do not hear back from you within 21 days we will close this case.”
},
{
limit: 14,
reminder: “We continue to look for your feedback and want to make sure we have assisted in providing you what you need. We have not heard from you for 14 days. If we do not hear back from you within 16 days we will close this case.”
},
{
limit: 30,
reminder: “Thank you, again, for your submission. We want to ensure that we have assisted you and provided the care you needed with respect to this ticket. For your convenience,we have not heard from you in 30 days, so we are closing this ticket on your behalf. We value your partnership and thank you for your feedback on how we can enhance your experience with My Company.”

}
];

const filter = [
(RequestType.Name="Question" or RequestType.Name="Issue"), // Requests of those types
(EntityState.Name = "Validation" or EntityState.Name = "Client Acceptance") // Which are in this state
].join(" and ");

const firstRulelimit = rules[0].limit;
const api = context.getService(“MyTicketSystem/api/v2”);
const requests = await api.queryAsync(“Request”, {
where: ${filter} and LastCommentDate <= DateTime.Now.AddDays(-1 * ${firstRulelimit}),
select: ‘{id,lastCommentDate,reminder:Comments.OrderByDescending(CreateDate).First().Description}’
});

const utils = require(“utils”);
let commands = ;
const today = new Date();

for (let request of requests) {
let diff = utils.differenceInDays(today, request.lastCommentDate);
console.log("Checking: " + JSON.stringify(request));
console.log(It was last commened ${diff} days ago.)
let comment = null;
let close = false;

let previousRule = null;
for (let i = 0; i < rules.length; i++) {
let currentRule = rules[i];
if (diff >= currentRule.limit && (!previousRule || request.reminder == previousRule.reminder)) {
comment = currentRule.reminder;
if (i == rules.length - 1) {
close = true;
}
}
previousRule = rules[i];
}

if (close) {
commands.push({
command: “MyTicketSystem:MoveToState”,
payload: {
resourceType: “Request”,
resourceId: request.id,
stateKind: “Final”
}
});
}

if (comment) {
commands.push({
command: “MyTicketSystem:CreateResource”,
payload: {
resourceType: “Comment”,
fields: {
General: { Id: request.id },
Description: comment
}
}
});
}
}

return commands;

Hi @kpjax,

The question doesn’t seem to be related to JSON Forms. Are you sure that you are using the JSON Forms framework?