Thought i had this worked out but struggling with how to trigger the next query using the results from JS.
I have the script below that checks the validity of 3 things
Is the date/time now within the date time allowed
Is the status listed as available
3 .Does the ticket name match the voucher name.
for the sake of testing i had the output printing to the console.log so i could check the JS was working.
I now want to trigger the next query when all three checks are successful and tried to Boolean with something like this but could not work out how to make it go to the next query
this is the code.
const TicketType = select1.selectedItem.Description.Standard;
const GetVoucherInfoData = {
Name: GetVoucherInfo.data.Name,
ValidFrom: GetVoucherInfo.data.ValidFrom,
ValidTo: GetVoucherInfo.data.ValidTo,
Status: GetVoucherInfo.data.Status
};
// Current date and time
const currentDate = moment().format('YYYY-MM-DD hh:mm:ss');
// Check if the voucher is valid using the isVoucherValid function
const isValid = isVoucherValid(GetVoucherInfoData, TicketType);
const TicketType = select1.selectedItem.Description.Standard;
const GetVoucherInfoData = {
Name: GetVoucherInfo.data.Name,
ValidFrom: GetVoucherInfo.data.ValidFrom,
ValidTo: GetVoucherInfo.data.ValidTo,
Status: GetVoucherInfo.data.Status
};
// Current date and time
const currentDate = moment().format('YYYY-MM-DD hh:mm:ss');
// Check if the voucher is valid using the isVoucherValid function
const isValid = isVoucherValid(GetVoucherInfoData, TicketType);
function isVoucherValid(GetVoucherInfoData, TicketType) {
const statusCheck = GetVoucherInfoData.Status === "Available";
const currentDate = new Date(); // Create a JavaScript Date object for the current date and time
const dateCheck = currentDate >= GetVoucherInfoData.ValidFrom && currentDate <= GetVoucherInfoData.ValidTo;
const nameCheck = GetVoucherInfoData.Name === TicketType;
return statusCheck && dateCheck && nameCheck;
}
We managed to get this working with the following code.
const TicketType = select1.selectedItem.Description.Standard;
const GetVoucherInfoData = {
Name: GetVoucherInfo.data.Name,
ValidFrom: GetVoucherInfo.data.ValidFrom,
ValidTo: GetVoucherInfo.data.ValidTo,
Status: GetVoucherInfo.data.Status
};
// Current date and time
const currentDate = moment().format('YYYY-MM-DD hh:mm:ss');
// Check Ticket Type and Ticket Name match
if (GetVoucherInfoData.Name === TicketType) {
console.log("Voucher Name matches Ticket Type.");
} else {
console.log("Voucher Name does not match Ticket Type.");
}
// Check if Current Date and Time match Ticket CheckValidity.data
if (currentDate >= GetVoucherInfoData.ValidFrom && currentDate <= GetVoucherInfoData.ValidTo) {
console.log("Voucher is within the valid period.");
} else {
console.log("Voucher is not within the validity period.");
}
// Check Status of ticket in swiftpos
if (GetVoucherInfoData.Status === "Available") {
console.log("Voucher is available.");
} else {
console.log("Voucher is not available.");
}
// Check if Ticket Type, Validity, and Status are all valid
const isTicketValid = GetVoucherInfoData.Name === TicketType;
const isValidityValid =
currentDate >= GetVoucherInfoData.ValidFrom &&
currentDate <= GetVoucherInfoData.ValidTo;
const isStatusValid = GetVoucherInfoData.Status === 'Available';
if (isTicketValid && isValidityValid && isStatusValid) {
const queryProcess = UseVoucherProcess.trigger();
} else {
if (!isTicketValid) {
console.log("Ticket Type is not valid.");
}
if (!isValidityValid) {
console.log("Validity period is not valid.");
}
if (!isStatusValid) {
console.log("Status is not valid.");
}
}
It now moves on and actually moves on to the "Process api query" and receives the expected response, which im now trying to copy into the finalize sale query.
This is related to the other ticket about copying the response you were helping with.