would like alert to popup when we click ‘re-assign reviewer’ to indicate a list of reviewers from Gsheet for the user to select from. however the sweet alert is not showing up when i run this script, the error seems to be due to InputOptionsPromise, how can i correct this please? i am completely new to Google Apps Script, please i would appreciate some help, thank you!
if (action == 'Prepared') {
Swal.fire({
title: "Insert Google Drive Folder Link",
input: 'text',
inputPlaceholder: `Enter link for ${formName}`
}).then((result) => {
if ((result.value).includes("drive.google.com/drive/folders/")) {
Swal.fire({
title: 'Please check reviewer',
text: "Email will be sent to: " + newData[0]['Assigned Checker'],
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, send!',
cancelButtonText: 'Change reviewer'
}).then((checking) => {
if (checking.isConfirmed) {
//ACTION WHEN SEND IS CONFIRMED
Swal.fire({
icon: 'success',
title: 'Task has been prepared',
showConfirmButton: false,
timer: 1500
})
google.script.run.update_dashboard(id, newData[0], action, sheetName, result.value, newData[0]['Assigned Checker'].replace(' (cover)', ''));
}
else {
Swal.fire({
title: 'Select Reviewer',
input: 'select',
inputOptions: inputOptionsPromise,
inputPlaceholder: 'Select Reviewer',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value != '') {
resolve();
} else {
reject('You need to select a reviewer')
alert('Select reviewer required')
}
})
}
}).then((address) => {
if (address.isConfirmed) {
Swal.fire({
type: 'success',
html: 'Email will be sent to: ' + address.value
})
google.script.run.update_dashboard(id, newData[0], action, sheetName, result.value, address.value);
}
})
}
})
}
else {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Please insert Google Drive Folder Link. Folder path is required.',
color: '#716add',
})
}
});
return
}
else if (action != 'Prepared') {
Swal.fire({
icon: 'success',
title: 'Task has been ' + action,
showConfirmButton: false,
timer: 1500
})
google.script.run.update_dashboard(id, newData[0], action, sheetName, newData[0]['Link']);
}
}
function tagPSC () {
var id = $("#formID").val();
Swal.fire({
title: "Enter Pre-Submission Checklist ID:",
text: "UID can be found in checklist tab",
input: 'text',
inputPlaceholder: 'e.g.: 3e44ead7-82c7-4782-a58c-471106c05d56',
showCancelButton: true
}).then((result) => {
if (result.value.length == 36) {
google.script.run.tag_psc_dashboard(id, result.value);
Swal.fire({
icon: 'success',
title: 'UID tagged successfully',
showConfirmButton: false,
timer: 1500
})
}
else {
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Please insert valid unique ID generated from Pre-Submission Checklist.',
color: '#716add',
})
}
});
}
function promiseLoadout () {
waitFor(_ => selectLi != null && userMapping != null)
.then(_ =>
(promiseResolution(selectLi, userMapping, 'val'),
google.script.run.withSuccessHandler(function(data) {
var promiseOutput = {}
JSON.parse(data).forEach(obj=>{
promiseOutput[obj['userName']] = obj['userID'] + "@maribank.com.sg"
})
window.inputOptionsPromise = new Promise(function (resolve) {
// get your data and pass it to resolve()
setTimeout(function () {
resolve(promiseOutput)
}, 2000)
})
}).convertToJson("Users"))
);
}
function reassign () {
var id = $("#formID").val();
Swal.fire({
title: 'Re-Assign Maker or Checker?',
showDenyButton: true, showCancelButton: false,
confirmButtonText: `Maker`,
denyButtonText: `Checker`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire({
title: 'Select new preparer',
input: 'select',
inputOptions: inputOptionsPromise,
inputPlaceholder: 'Select new preparer',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value != '') {
resolve();
} else {
reject('You need to select a preparer')
alert('Select preparer required')
}
})
}
}).then((address) => {
if (address.isConfirmed) {
Swal.fire({
type: 'success',
html: 'Preparer has been changed to: ' + address.value
})
google.script.run.reassign_dashboard('maker', id, address.value);
}
})
} else if (result.isDenied) {
Swal.fire({
title: 'Select new reviewer',
input: 'select',
inputOptions: inputOptionsPromise,
inputPlaceholder: 'Select new reviewer',
showCancelButton: true,
inputValidator: function(value) {
return new Promise(function(resolve, reject) {
if (value != '') {
resolve();
} else {
reject('You need to select a reviewer')
alert('Select reviewer required')
}
})
}
}).then((address) => {
if (address.isConfirmed) {
Swal.fire({
type: 'success',
html: 'Reviewer has been changed to: ' + address.value
})
google.script.run.reassign_dashboard('checker', id, address.value);
}
})
}
});
}