how to restrict not moving to next state it should be in same state when my conditions not satisfy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 01:34 AM
pls check below on change client script on problem table
when ever user select source as incident problem etc and under related list if no records associated then it should restrict not moving to assigned state and my code saving its moving to next state
below is script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 02:49 AM
Hi @Teja3 ,
You are using an OnChange client script, which does not execute on the server side. This means that the record will be saved without any issues. If you want to prevent the record from being saved when there are no records present in your related list, you'll need to use a Business Rule(onBefore Update) instead.
You can use gs.setAbortAction(true); to prevent the current action from completing in business rule.
[Notes - One benefit of writing a Business Rule is that it executes in list view as well. So, if someone changes the state in the list view, the Business Rule will run, and if the condition is met, it will prevent the record from being updated.]
Hope this help you
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 03:01 AM
I've tried using business rule and used setabortaction its preventing once but if we refresh the form it remains same state if we save it then its moving to next state this should not be the case
how can i prevent this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 03:08 AM
Could you please provide details about what you wrote in the Business Rule, when it triggers, and under what circumstances the record should not be saved?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 03:22 AM - edited 10-23-2024 03:23 AM
Before insert and update
state is new and assigned to changes
(function executeRule(current, previous) {
if (current.state == '1') { // Checks if state is new
var source = current.u_source;
var hasRelatedRecords = false;
var infomessage = '';
if (source == '0') {
// Check if there are associated incidents under the related list of IT Incident tab
var incidentGr = new GlideRecord('incident');
incidentGr.addQuery('problem', current.sys_id);
incidentGr.query();
if (incidentGr.next()) {
hasRelatedRecords = true;
}
infomessage = "Since the Source is selected as IT Incident, please associate an Incident in the IT Incident list of the relevant tabs below.";
} else if (source == '1') {
// Check if there are associated alerts under the related list of the alerts tab
var alertGr = new GlideRecord('em_alert');
alertGr.addQuery('incident', current.sys_id);
alertGr.query();
if (alertGr.next()) {
hasRelatedRecords = true;
}
infomessage = "Since the Source is selected as Event, please associate an alert in the Alerts list of the relevant tabs below.";
} else if (source == '4') {
// Check if there are associated problems under the related list of IT Problem tab
var problemGr = new GlideRecord('problem');
problemGr.addQuery('problem', current.sys_id);
problemGr.query();
if (problemGr.next()) {
hasRelatedRecords = true;
}
infomessage = "Since the Source is selected as IT Problem, please associate a problem in the IT Problems list of the relevant tabs below.";
} else if (source == '9') {
var servicereq = new GlideRecord('sc_req_item'); // Check if there are associated service requests under the related list of the service request tab
servicereq.addQuery('parent', current.sys_id);
servicereq.query();
if (servicereq.next()) {
hasRelatedRecords = true;
}
infomessage = "Since the source is selected as Service Request, please associate a request in the Service Request of the relevant tabs below.";
}
if (!hasRelatedRecords && current.state == '1') {
// Revert the state to the previous value
gs.addInfoMessage(infomessage);
current.setAbortAction(true);
}
}
})(current, previous);