Business rule check related list has only p1 p2 incidents

Community Alums
Not applicable

Hi community,

 

I need to write a business rule to check in the change request there's a related list called incidents resolved, so in the change type is emergency I need only p1 and p2 incidents to be selected can someone suggest the business rule so that this scenario can work

1 ACCEPTED SOLUTION

Najmuddin Mohd
Mega Sage

Hi @Community Alums ,

So, when you update the related list, it's actually associating the change on the incident record.

So, write the business rule on Incident table. 
Before - Update
Conditions,
< Field which stores the change number on the incident when associated from change request > < Changes> 

GlideRecord the Change table
Query the change record, 
If the change is Emergency 

         Nested If the current incident is P1 or P2

Else 
      Abort the action.


Hope this helps.

Regards,
Najmuddin.


View solution in original post

2 REPLIES 2

Sid_Takali
Kilo Patron
Kilo Patron

Hi @Community Alums Try below code on Before Insert Update BR on Change Request table

(function executeRule(current, previous /*null when async*/) {
    if (current.type == 'Emergency') {
        var resolvedIncidents = new GlideRecord('incident');
        resolvedIncidents.addQuery('change_request', current.sys_id); 
        resolvedIncidents.addQuery('priority', 'IN', '1,2'); 
        resolvedIncidents.query();

        var validIncidents = true;
        while (resolvedIncidents.next()) {
            if (resolvedIncidents.priority != '1' && resolvedIncidents.priority != '2') {
                validIncidents = false;
                break;
            }
        }

        if (!validIncidents) {
            gs.addErrorMessage('For Emergency change requests, only P1 and P2 incidents are allowed.');
            current.setAbortAction(true); // Prevents saving if validation fails
        }
    }

})(current, previous);

  

Najmuddin Mohd
Mega Sage

Hi @Community Alums ,

So, when you update the related list, it's actually associating the change on the incident record.

So, write the business rule on Incident table. 
Before - Update
Conditions,
< Field which stores the change number on the incident when associated from change request > < Changes> 

GlideRecord the Change table
Query the change record, 
If the change is Emergency 

         Nested If the current incident is P1 or P2

Else 
      Abort the action.


Hope this helps.

Regards,
Najmuddin.