This action should first look at 8 different fields and make sure they are all populated. If any of them are not populated then it should display a message saying "All fields must be completed" and take no further action.
If all 8 fields are populated then there is some if/then logic to update a field and display a message. Once it updates the field and displays the message then no further action should be taken.
In both cases (if one or more fields isn't populated OR if all 8 fields are populated) it is acting as expected except that it then tries to create a new record. I don't want it to create a new record. How can I get this to stop?
function onClick(event) {
if (event) {
event.preventDefault(); // Stops the default form submission
}
var requiredFields = [
'u_is_this_a_new_product_service_or_new_process',
'u_does_this_project_have_significant_operational_impacts',
'u_does_this_require_technology_operations_resources',
'u_does_this_project_span_across_multiple_lines_of_business',
'u_does_this_project_have_legal_compliance_and_or_fraud_risk',
'u_is_this_project_the_result_of_an_identified_issue_issue_on_the_issue_tracker',
'u_does_this_project_have_an_impact_on_the_membership',
'u_does_this_project_involve_a_third_party_relationship_i_e_vendor'
];
// Check if any required field is "None" or empty
for (var i = 0; i < requiredFields.length; i++) {
if (g_form.getValue(requiredFields[i]) === "None" || g_form.getValue(requiredFields[i]) === "") {
showDialog("Missing Information", "All fields must be completed before Evaluation.");
return false; // Stop execution
}
}
// Calculate Total Risk Score
var totalRiskScore = 0;
requiredFields.forEach(function(field) {
if (g_form.getValue(field) === "Yes") {
totalRiskScore += 1;
}
});
// Update the total risk score
g_form.setValue('u_total_risk_score', totalRiskScore);
// Get the value of "Is this a new product/service/process?"
var isNewProductServiceOrProcess = g_form.getValue('u_is_this_a_new_product_service_or_new_process');
// Determine Risk Score Result
var riskScoreResult = "";
if (isNewProductServiceOrProcess === "Yes" || totalRiskScore >= 5) {
riskScoreResult = "High Risk: Risk Assessment must be conducted";
} else if (isNewProductServiceOrProcess === "No" && totalRiskScore === 4) {
riskScoreResult = "Medium Risk: Risk assessment is optional.";
} else if (isNewProductServiceOrProcess === "No" && totalRiskScore <= 3) {
riskScoreResult = "Low Risk: Risk assessment does not need to be conducted";
}
// Update the Risk Score Result field
g_form.setValue('u_risk_score_result', riskScoreResult);
// Display final message in a dialog box
showDialog("Evaluation Complete", "Evaluation Complete: " + riskScoreResult);
return false; // Ensures no record is created
}
// Function to show a modal dialog
function showDialog(title, message) {
var dialog = new GlideModal("custom_dialog");
dialog.setTitle(title);
dialog.setBody("<p style='font-size:14px;'>" + message + "</p>", false, false);
dialog.addCloseButton("OK");
dialog.render();
}