Confusion between business rule use and client script use
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 04:35 AM
Hey everyone,
I have doubt about business rule and client script usage.
I have a requirement to add a logic to change records such that if change task has any change task open, change record can't move to "implemented" state from 'implement' state.
To move to implemented state user has to click an ui action button "Implemented" on change record header.
Now, my doubt is what should i use business rule or client script to achieve this as i am not very through with usage of both of these
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 05:17 AM
Thankyou, but I think you are talking about condition field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 05:35 AM
@PriyanshuVerma1 You can check the condition in the condition field of the UI Action or check the condition inside the script field and show an error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 04:52 AM - edited ‎02-22-2024 07:54 AM
Hey, I tried doing that. I added. The issue is that now button is not visible to end user if change task is open.
I want to show them the button but restrict them by showing error message.
I am using below code but it is not working . i am using ui action script to check and abort Please help with correction of code, state
function moveToImplement(){
var gr_tsk = new GlideRecord('change_task');
gr_tsk.addEncodedQuery(state=1^change_request.sys_id==current.sys_id); // state = 1 is open state of change task and change request sys id associayed to change task is same that of current record sysid.
gr_tsk.query();
if(gr_tsk.hasNext){
gs.addErrorMessage("Cannot close change record. There are change tasks are associayed");
current.setAbortAction(true);
}
else{
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "review");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_review");
});
}}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2024 10:47 AM - edited ‎02-14-2024 10:47 AM
HI @PriyanshuVerma1 ,
I trust you are doing great.
For your requirement, you'll need to use a combination of both a Client Script and a Business Rule to ensure a robust solution. Here's why and how you can implement this:
Why Both?
- Client Script: Used for real-time, client-side validations when a user interacts with the form (e.g., clicking the "Implemented" UI Action button). It can prevent the form from being submitted but cannot enforce rules when records are updated through other means (like scripts, integrations, or other automated processes).
- Business Rule: Operates on the server side, ensuring that your validation logic is enforced regardless of how the record is updated. This is crucial for maintaining data integrity and enforcing business logic across all update mechanisms.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi