Business Rule:-A business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried.
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat
‎06-11-2020 05:59 AM
How to hide ui action via business rule
Solved! Go to Solution.
‎06-11-2020 11:20 PM
its fine to have business rule and ui action will also evaluate your business rule script if it will not fulfill your condition.
make sure the business rule order is 100.
‎06-11-2020 06:01 AM
why do you want to hide ui action using business rule ? that will not work.
simply mention the condition in ui action condition field.
‎06-11-2020 06:11 AM
Hi Akhila
Both are the Different Things.
UI actions include the buttons, links, and context menu items on forms and lists. Configure UI actions to make the UI more interactive, customized, and specific to user activities. You can do this using UI Policy on Form Design.
Business Rule:-A business rule is a server-side script that runs when a record is displayed, inserted, updated, or deleted, or when a table is queried.
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat
‎06-11-2020 06:12 AM
I have written a Business rule which shows an error message when planned start date is greater than cab date..
function _checkLeadTime(){
var startDate = new GlideDateTime(current.start_date); //creates a GlideDateTime object for the Start Date
var cab = new GlideDateTime(current.u_cab_date); //creates a GlideDateTime object for the CAB Date
//gs.addInfoMessage(startDate);
// gs.addInfoMessage(cab);
if(startDate == ''){
current.isAbortAction(false); //if no date entered allow submit
} else if ((startDate.before(cab))&& (current.type=='Comprehensive')){ //check if start_date is before cab_date
gs.addErrorMessage('This change request cannot be submitted as the Provided Start Date is either before the CAB meeting or on the same day as CAB meeting. Please raise an "Expedited" Change"');
current.setAbortAction(true); //if start date before cab date do not allow submit
}
else if ((startDate.after(cab))&& (current.type=='expedited')){ //check if start_date is before cab_date
gs.addErrorMessage('This change request cannot be submitted as it is planned after the CAB meeting. Expedited change request type is only used for changes that are urgent in nature and cannot wait until the next CAB meeting . Please raise a "Normal" Change.');
current.setAbortAction(true); //if start date before cab date do not allow submit
}
}
checkDeadline();
we have a submit for approval button with the below code.
CONDITION :!current.isNewRecord() && current.state == 40 && current.approval=='not requested' && gs.hasRole("itil") && current.type !='Routine'
function validateApprovalSubmission() {
if (g_form.getValue("type") == "Comprehensive"){
if(g_form.getValue('u_fill_risk_assessment_verification') == 'true' && g_form.getValue('risk') == ''){
g_form.clearMessages();
g_form.addErrorMessage('Please Execute Risk Calculation before Submitting for Approval');
return false;
}
if(g_form.getValue('risk') == '')
{
g_form.clearMessages();
g_form.addErrorMessage('Please Fill out Risk Assessment under Related links and then Execute Risk Calculation before Submitting for Approval');
return false;
}
}
if (g_form.getValue("type") == "expedited"){
if(g_form.getValue('u_fill_risk_assessment_verification') == 'true' && g_form.getValue('risk') == ''){
g_form.clearMessages();
g_form.addErrorMessage('Please Execute Risk Calculation before Submitting for Approval');
return false;
}
if(g_form.getValue('risk') == '')
{
g_form.clearMessages();
g_form.addErrorMessage('Please Fill out Risk Assessment under Related links and then Execute Risk Calculation before Submitting for Approval');
return false;
}
}
var ga = new GlideAjax('checkP1P2atUpdate');
ga.addParam('sysparm_name','checkP1P2atUpdateClient');
ga.addParam('sysparm_sys_id',g_form.getUniqueValue());
ga.getXMLWait();
var an=ga.getAnswer();
if(an!="true") {
alert("Please attach a P1/P2 incident before submitting for approval");
return false;
}
}
gsftSubmit(null, g_form.getFormElement(), 'requestApproval');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
submitForApproval();
function submitForApproval() {
gs.log('============== in submitForApproval===========');
action.setRedirectURL(current);
current.approval='requested';
current.state = 55; // Set Awaiting Technology Approval
gs.log('============== in submitForApproval - after state set===========');
if(current.isNewRecord()) {
current.insert();
} else {
current.update();
}
gs.log('============== in submitForApproval - after update===========');
}
Even though a business rule error is der this ui action works but data is not updated.. on refresh we will get the old page itself.. How to restrict this.
‎06-11-2020 06:20 AM
first thing i would like to add here, you have duplicate thread for same question. please dont open duplicate thread, it will be easy for us to follow and guide you.
now coming to your issue, are you sure your ui action code is correct, because if i see your client side code of ui action , seems like same condition has been written multiple times. correct me if i am wrong.
another question , please confirm why are you using below code in your ui action server side part ?
is it possible if you can add more details about your ui action ? eg: what exactly you want to perform with your ui action ?
if(current.isNewRecord()) {
current.insert();
} else {
current.update();
}
gs.log('============== in submitForApproval - after update===========');
}