How to hide ui action via business rule

akhila13
Tera Expert

How to hide ui action via business rule

1 ACCEPTED SOLUTION

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. 

View solution in original post

9 REPLIES 9

Harsh Vardhan
Giga Patron

why do you want to hide ui action using business rule ? that will not work. 

 

simply mention the condition in ui action condition field. 

Gaurav Shirsat
Mega Sage

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.

UI action controls

You can create a UI action to provide any of these controls:
  • A button on a form.
  • A context menu item on a form that appears when you open the form context menu or right-click the form header.
  • A related link in a form.
  • A button in the banner on top of a list.
  • A button at the bottom of a list.
  • A context menu item on a list that appears when you open the list context menu or right-click the list header.
  • A menu item for the action choice list at the bottom of a list.
  • A related link at the bottom of a list.

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.

Use business rules to accomplish tasks like automatically changing values in form fields when certain conditions are met, or to create events for email notifications and script actions.
Note: Business rules can make use of scripts to take actions on records in the database. However, there are several other scripting options available on the platform, such as client scripts and UI actions.
 

 

Please Mark Correct and Helpful

Thanks and Regards

Gaurav Shirsat

 

akhila13
Tera Expert

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.

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===========');
}