Hello everyone,
Question / Problem
I am trying to block Process Management from being executed when a specified condition is met by using Process Management API.
If you have any idea about the case, please help!
Current Situation
So the scenario is to get the data from an App and check it with the other App before running PUT API, but for now, I can only block PUT API.
The status is still changing after the condition is met. It seems that I can pop up an error or return an error(false) to the event of process management.
Code / Attempts
(function () {
"use strict";
kintone.events.on("app.record.detail.process.proceed", (eventLeave) => {
const record = eventLeave.record;
const status = record.Status.value;
const newStatus = eventLeave.nextStatus.value;
if (status !== "Approved" && newStatus === "Approved") {
const record = eventLeave.record;
const User = "Text_Copy";
const Req_Date = record.ReqDate.value;
const Leave = "Leave_Type";
const Used = record.Total_Used.value;
const Note = record.Note_Leave.value;
const query = 'Text_Copy = "' + record[User].value + '" order by $id';
const fields = "&fields[0]=$id&fields[1]=Text_Copy";
const A = kintone.api(
kintone.api.url("/k/v1/records", true) +
"?app=10&query=" +
query +
fields,
"GET",
{},
function (resp) {
// success
const recid = resp.records[0].$id.value;
const TableName = resp.records[0].Text_Copy.value;
if (record[Leave].value === "Sick") {
const body = {
value: {
Date_Sick: {
type: "DATE",
value: Req_Date,
},
Notes_Sick: {
type: "SINGLE_LINE_TEXT",
value: Note,
},
Number_Leave_Sick: {
type: "NUMBER",
value: "-" + Used,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true) + "?app=10&id=" + recid,
"GET",
{},
function (resp) {
// success
const record2 = resp.record;
const sickTableValue = record2.Sick_Table.value;
sickTableValue.push(body);
const AvailSick = record2.Current_Avail_Sick.value;
if (AvailSick - Used < 0) {
eventLeave.error = "Insufficient Leave";
return eventLeave.error;
} else {
const updateData = {
app: 10,
id: record2.$id.value,
record: {
Sick_Table: {
value: sickTableValue,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true),
"PUT",
updateData,
function (resp) {
console.log("Update Sick Time");
}
);
}
}
);
} else if (record[Leave].value === "Personal") {
const body = {
value: {
Date_Person: {
type: "DATE",
value: Req_Date,
},
Notes_Person: {
type: "SINGLE_LINE_TEXT",
value: Note,
},
Number_Leave_Person: {
type: "NUMBER",
value: "-" + Used,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true) + "?app=10&id=" + recid,
"GET",
{},
function (resp) {
// success
const record2 = resp.record;
const personTableValue = record2.Person_Table.value;
const AvailPerson = record2.Current_Avail_Person.value;
personTableValue.push(body);
if (AvailPerson - Used < 0) {
eventLeave.error = "Insufficient Leave";
return eventLeave;
} else {
const updateData = {
app: 10,
id: record2.$id.value,
record: {
Person_Table: {
value: personTableValue,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true),
"PUT",
updateData,
function (resp) {
console.log("Update Person Time");
}
);
}
}
);
} else if (record[Leave].value === "Vacation") {
const body = {
value: {
Date_Vac: {
type: "DATE",
value: Req_Date,
},
Notes_Vac: {
type: "SINGLE_LINE_TEXT",
value: Note,
},
Number_Leave_Vac: {
type: "NUMBER",
value: "-" + Used,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true) + "?app=10&id=" + recid,
"GET",
{},
function (resp) {
// success
const record2 = resp.record;
const vacTableValue = record2.Vac_Table.value;
const AvailVac = record2.Current_Avail_Vac.value;
vacTableValue.push(body);
if (AvailVac - Used < 0) {
eventLeave.error = "Insufficient Leave";
return eventLeave;
} else {
const updateData = {
app: 10,
id: record2.$id.value,
record: {
Vac_Table: {
value: vacTableValue,
},
},
};
kintone.api(
kintone.api.url("/k/v1/record", true),
"PUT",
updateData,
function (resp) {
console.log("Update Vac Time");
}
);
}
}
);
}
return eventLeave;
}
);
}
});
})();
Error Message
Screenshots are helpful
Desired Outcome / Expected Behavior
Screenshots are helpful
Referenced Resources
List the tutorials, API docs, & help article you read