Hi All,
Need your help , i got stucked to find a way to force users to write something to when they Click Process or Reject Btn , since the current script can be bypassed when click Submit, Any thoughts to do it.
<script>
let Permission_Groups = ["Approvers"],
sp, context;
hide_Progress();
$(window).bind("load", function (){
initiate_Script()
});
async function initiate_Script () {
sp = pnp.sp;
context = _spPageContextInfo;
$("input[value*='Close']:visible").before(`<input type='button' class="action_btn" id="btn_Reject" onClick='Change_Status(this)' value='Reject'>`)
$("input[value*='Close']:visible").before(`<input type='button' class="action_btn" id="btn_Process" onClick='Change_Status(this)' value='Process'>`)
$("input[value*='Close']:visible").before(`<input type='button' class="action_btn" id="print_Page" onClick='window.print()' value='Print'>`)
if (await check_Permission()) {
if ($('a[name="SPBookmark_Processed"]').closest("td").next().text().trim() === "Yes") {
$("#btn_Reject, #btn_Process").attr("disabled", true)
}
}
let action_btn_tbl = $(".action_btn").closest("table").clone();
$("table.ms-formtable").next().find("table").remove();
$(action_btn_tbl).addClass("action_btn_tbl")
$("table.ms-formtable").after(action_btn_tbl);
}
async function check_Permission() {
let res = await sp.web.currentUser.groups.get();
let groups = res.map(item => item.LoginName);
let permission = false;
groups.forEach(g => {
Permission_Groups.includes(g) ? permission = true :"";
});
return permission;
}
function Change_Status(status){
let item_ID = getUrlParameter("ID");
let selected_Option = $(status).val();
if (selected_Option === "Process") {
alertify.prompt( 'Provide Authorized Inspector No', '', '',
function(evt, value) {
show_Progress();
let item_Obj = {
Status : "Processed",
Processed_x0020_ById : context.userId,
Processing_x0020_Time : new Date().toISOString(),
Processed : "Yes",
Inspector_No : value,
};
sp.web.lists.getByTitle(context.listTitle).items.getById(item_ID).update(item_Obj).then(res => {
hide_Progress();
$("#SPFieldChoice").text("Processed");
$("a[name='SPBookmark_Inspector_No']").closest("td").next().text(value)
alertify.success("Request has been processed.", 3, function () {
$("input[value='Close']").click();
});
}).catch(e => {
hide_Progress();
alertify.error("There is some issue occurs while updating the <strong>Status</strong>");
});
},
function() {
alertify.error('Cancel')
}
).set('labels', {ok:'Submit', cancel:'Cancel'});
} else if (selected_Option === "Reject") {
alertify.prompt( 'Provide valid reason to reject this request.', 'Reason', 'Enter reason here..',
function(evt, value) {
show_Progress();
let item_Obj = {
Status : "Rejected",
Processed_x0020_ById : context.userId,
Processing_x0020_Time : new Date().toISOString(),
Processed : "Yes",
Rejection_x0020_reason : value
};
sp.web.lists.getByTitle(context.listTitle).items.getById(item_ID).update(item_Obj).then(res => {
hide_Progress();
$("#SPFieldChoice").text("Rejected");
$("a[name='SPBookmark_Rejection_x0020_reason']").closest("td").next().text(value)
alertify.success("Request has been Rejected.", 3, function() {
$("input[value='Close']").click();
});
}).catch(e => {
hide_Progress();
alertify.error("There is some issue occurs while updating the <strong>Status</strong>");
});
},
function() {
alertify.error('Cancel')
}
).set('labels', {ok:'Submit', cancel:'Cancel'});
}
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function show_Progress() {
$("#loader").show();
}
function hide_Progress() {
$("#loader").hide();
}
</script>