Skip to main content

showMessage()

Last updated 24/01/2023


The following code shows a message in the UI if the value entered in the Discount Code field can't be validated.


JavaScript
Show message if invalid discount code
function ValidDiscountCode(five, context, result) {
const discountCodes = ['10456A', 'W2341', 'HA888', 'PP8989', 'M567'];

for (let i = 0; i < discountCodes.length ; i++) {
if (five.field.DiscountCode === discountCodes[i]) {
return five.success();
}
}

five.showMessage('Unknown discount code');

return five.success(result);
}


TypeScript
Show message if invalid discount code
function ValidDiscountCode(five: Five, context: any, result: FiveError) : FiveError  {
const discountCodes = new Array<string>('10456A', 'W2341', 'HA888', 'PP8989', 'M567');

for (let i = 0; i < discountCodes.length ; i++) {
if (five.field.DiscountCode === discountCodes[i]) {
return five.success();
}
}

five.showMessage('Unknown discount code');

return five.success(result);
}