Create Problem UI Action Issue

purdue
Kilo Sage

Hello,

We are running into an issue with a business rule is running but not stopping processing of a ui action.   

When using the create a problem ui action the problem record is created and linked to the incident, however due to the br running which requires the user to attach impacted countries through related list the form is refreshed and the related problem is no linked to the incident leaving a orphaned problem record.  Any suggestions are welcome and appreciated.   

The before business rule runs when inc category is Broadcast Transmission and assigned group is BCC and state changes.  The advanced condition is 

var gr = new GlideRecord("u_m2m_core_country_incident");
gr.addQuery("u_incident", current.sys_id);
gr.query();
if (!gr.next()) {
gs.addErrorMessage("Please attach all impacted countries to the incident form before updating the incident state");
current.setAbortAction(true);
}
Here is the Incident UI Action.
 
var item = current.cmdb_ci;
if (JSUtil.notNil(item)) {
var prob = new IncidentUtils().getProblemFromIncident(current);
if (prob != undefined) {
current.problem_id = prob.insert();
if (current.state != IncidentState.RESOLVED) {
current.state = IncidentState.ON_HOLD;
if (current.isValidField("hold_reason"))
current.hold_reason = IncidentState.AWAITING_PROBLEM;
}
if (GlidePluginManager.isActive("com.snc.best_practice.problem.madrid")) {
var problemV2Util = new ProblemV2Util();
problemV2Util.copyAttachments(current, prob);
problemV2Util.copyAttachedKnowledge(current, prob);
}
current.update();
gs.addInfoMessage(gs.getMessage("Problem {0} created", prob.number));
action.setRedirectURL(prob);
action.setReturnURL(current);
} else {
action.setRedirectURL(current);
}
} else {
action.setRedirectURL(current);
gs.addErrorMessage('CI field is required before creating a problem record');
}
1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

I think the solution would be to add this script to the UI action too, so that impacted countries are associated before a problem record is associated.

var gr = new GlideRecord("u_m2m_core_country_incident");
gr.addQuery("u_incident", current.sys_id);
gr.query();
if (!gr.next()) {
gs.addErrorMessage("Please attach all impacted countries to the incident form before updating the incident state");
}
else
{
var item = current.cmdb_ci;
if (JSUtil.notNil(item)) {
var prob = new IncidentUtils().getProblemFromIncident(current);
if (prob != undefined) {
current.problem_id = prob.insert();
if (current.state != IncidentState.RESOLVED) {
current.state = IncidentState.ON_HOLD;
if (current.isValidField("hold_reason"))
current.hold_reason = IncidentState.AWAITING_PROBLEM;
}
if (GlidePluginManager.isActive("com.snc.best_practice.problem.madrid")) {
var problemV2Util = new ProblemV2Util();
problemV2Util.copyAttachments(current, prob);
problemV2Util.copyAttachedKnowledge(current, prob);
}
current.update();
gs.addInfoMessage(gs.getMessage("Problem {0} created", prob.number));
action.setRedirectURL(prob);
action.setReturnURL(current);
} else {
action.setRedirectURL(current);
}
} else {
action.setRedirectURL(current);
gs.addErrorMessage('CI field is required before creating a problem record');
}

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

I think the solution would be to add this script to the UI action too, so that impacted countries are associated before a problem record is associated.

var gr = new GlideRecord("u_m2m_core_country_incident");
gr.addQuery("u_incident", current.sys_id);
gr.query();
if (!gr.next()) {
gs.addErrorMessage("Please attach all impacted countries to the incident form before updating the incident state");
}
else
{
var item = current.cmdb_ci;
if (JSUtil.notNil(item)) {
var prob = new IncidentUtils().getProblemFromIncident(current);
if (prob != undefined) {
current.problem_id = prob.insert();
if (current.state != IncidentState.RESOLVED) {
current.state = IncidentState.ON_HOLD;
if (current.isValidField("hold_reason"))
current.hold_reason = IncidentState.AWAITING_PROBLEM;
}
if (GlidePluginManager.isActive("com.snc.best_practice.problem.madrid")) {
var problemV2Util = new ProblemV2Util();
problemV2Util.copyAttachments(current, prob);
problemV2Util.copyAttachedKnowledge(current, prob);
}
current.update();
gs.addInfoMessage(gs.getMessage("Problem {0} created", prob.number));
action.setRedirectURL(prob);
action.setReturnURL(current);
} else {
action.setRedirectURL(current);
}
} else {
action.setRedirectURL(current);
gs.addErrorMessage('CI field is required before creating a problem record');
}

Please mark this response as correct or helpful if it assisted you with your question.

Hello,

Actually this is not working.   After ui action is clicked it is sending me back to the list of incidents and displaying the attachment message.

To stay on the incident you can use action.setRedirectURL(current);

 

var gr = new GlideRecord("u_m2m_core_country_incident");
gr.addQuery("u_incident", current.sys_id);
gr.query();
if (!gr.next()) {
gs.addErrorMessage("Please attach all impacted countries to the incident form before updating the incident state");
action.setRedirectURL(current);
}
else
{
var item = current.cmdb_ci;
if (JSUtil.notNil(item)) {
var prob = new IncidentUtils().getProblemFromIncident(current);
if (prob != undefined) {
current.problem_id = prob.insert();
if (current.state != IncidentState.RESOLVED) {
current.state = IncidentState.ON_HOLD;
if (current.isValidField("hold_reason"))
current.hold_reason = IncidentState.AWAITING_PROBLEM;
}
if (GlidePluginManager.isActive("com.snc.best_practice.problem.madrid")) {
var problemV2Util = new ProblemV2Util();
problemV2Util.copyAttachments(current, prob);
problemV2Util.copyAttachedKnowledge(current, prob);
}
current.update();
gs.addInfoMessage(gs.getMessage("Problem {0} created", prob.number));
action.setRedirectURL(prob);
action.setReturnURL(current);
} else {
action.setRedirectURL(current);
}
} else {
action.setRedirectURL(current);
gs.addErrorMessage('CI field is required before creating a problem record');
}

Please mark this response as correct or helpful if it assisted you with your question.

Kieran Anson
Kilo Patron

Hi,

What behaviour are you wanting to achieve? Are you wanting to prevent the problem being created? Its not clear the business process you're trying to solve, and ultimately the issue you're running into technically