Business Rule

neeraj22671
Tera Contributor

Hello Guys, 

There is a business rule which closed the related Incidents if the problem state is 4.

Below is the code:  

if (current.problem_state.changesTo(4)) {
   closeRelatedIncidents(current);
   closeRelatedTasks(current);
}

//
// Close any incidents that are related to the current problem
//
function closeRelatedIncidents(me) {
  var incident = new GlideRecord("incident");
  incident.addQuery("problem_id", "=", me.sys_id);
  incident.query();
  while (incident.next()) {
    if ( incident.active == true ){
      var msg = gs.getMessage("Incident {0} closed based on closure of problem {1}", [incident.number, me.number]);
      gs.print(msg);
      incident.incident_state.setValue(IncidentState.CLOSED);
      incident.active.setValue(false);
      incident.comments = msg;
      incident.update();
    }
  }
}
var msg = gs.getMessage("Incident {0} closed based on closure of problem {1}", [incident.number, me.number]);
 
My question :  What is the meaning of below code lines in this business rule.
1)var msg = gs.getMessage("Incident {0} closed based on closure of problem {1}", [incident.number, me.number]); 
2) incident.addQuery("problem_id", "=", me.sys_id); - Why we used me here. 
 
 
neeraj22671_0-1707106839734.png

 

 
1 ACCEPTED SOLUTION

Rene El Hamzh
Kilo Sage

Hi @neeraj22671,

 

1) getMessage() accepts a second parameter to replace the placeholders in the message. For example, {0} will be replaced with the value of incident.number and {1} with the value of me.number.

 

2) me is a GlideRecord that is passed to the function closeRelatedIncidents(me) as a parameter.
 

Best regards,

Rene

 

Please mark as correct/helpful if my answer helped you!

View solution in original post

1 REPLY 1

Rene El Hamzh
Kilo Sage

Hi @neeraj22671,

 

1) getMessage() accepts a second parameter to replace the placeholders in the message. For example, {0} will be replaced with the value of incident.number and {1} with the value of me.number.

 

2) me is a GlideRecord that is passed to the function closeRelatedIncidents(me) as a parameter.
 

Best regards,

Rene

 

Please mark as correct/helpful if my answer helped you!