Hello, Sanjiv. Thanks for your response.
I´m facing a problem: after calling the script include, sysparm values are undefined. I can´t figure it out. Can you help me?
function OnAutoAssignGroup() {
var ci = g_form.getValue('cmdb_ci');
var category = g_form.getValue('category');
var subcategory = g_form.getValue('subcategory');
var contact_type = g_form.getValue('contact_type');
var assignment_group = g_form.getValue('assignment_group');
var confirmation = confirm(getMessage("Are you sure you want to make the change? If you are not a member of the assignment group, you will not be able to edit the form."));
if (confirmation == false) {
return false; // Abort change if answer is "no"
} else { // CONFIRMATION YES
if (contact_type == "redphone") {
alert("caiu no if pois é redphone");
var confirmRedphone = confirm("Canal é Redphone. Alterar para o grupo XPTO?");
if (confirmRedphone == false) {
return false;
} else {
g_form.setValue('assigned_to', '');
g_form.setValue('assignment_group', "8c1f64521bf74d10b7a7fc49cd4bcb28");
g_form.save();
return;
}
}
// SOLUTION TO HAVE THE GROUP IN THE MESSAGE FOR THE USER TO CONFIRM ------------ START
var autoAssignedGroupGA = new GlideAjax('AutoAssignGroupButton');
autoAssignedGroupGA.addParam('sysparm_name', 'initialize');
autoAssignedGroupGA.addParam('sysparm_ci', ci);
autoAssignedGroupGA.addParam('sysparm_category', category);
autoAssignedGroupGA.addParam('sysparm_subcategory', subcategory);
autoAssignedGroupGA.addParam('sysparm_assignment_group', assignment_group);
autoAssignedGroupGA.getXML(responseAssignedGroup);
}
function responseAssignedGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var confirmAutoAssignedGroup = confirm("Quer mesmo mudar para o grupo " + answer + "?");
if (confirmAutoAssignedGroup == false) {
return false; // Abort autoAssignment if answer is "no"
} else {
// SOLUTION TO HAVE THE GROUP IN THE MESSAGE FOR THE USER TO CONFIRM ------------ END
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), "u_auto_assign_group"); //MUST call the 'Action name' set in this UI Action
}
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined') {
runServer();
}
//Server-side function
function runServer() {
//CONFIGURATION ITEM
var ciGR = new GlideRecord('cmdb_ci_business_app');
ciGR.addQuery('name', current.cmdb_ci.name);
ciGR.query();
//CATEGORY AND SUBCATEGORY
var tableGR = new GlideRecord('dl_u_assignment');
tableGR.addQuery('category', current.category);
tableGR.addQuery('subcategory', current.subcategory);
tableGR.query();
current.setWorkflow(false);
if (current.contact_type == 'redphone') {
current.assignment_group = gs.getProperty('xpto');
current.assigned_to = '';
action.setRedirectURL(current);
current.update();
} else {
if (ciGR.next()) {
if (ciGR.support_group != '' && current.assignment_group != ciGR.support_group) {
current.assignment_group = ciGR.support_group;
} else if (current.assignment_group == ciGR.support_group) {
gs.addInfoMessage('Assignment Group already correctly assigned.');
} else {
if (tableGR.next()) {
if (current.assignment_group != tableGR.assignment_group) {
current.assignment_group = tableGR.assignment_group;
} else {
gs.addInfoMessage('Assignment Group already correctly assigned.');
}
} else {
current.assignment_group = '';
gs.addInfoMessage('No Assignment Group.');
}
}
current.assigned_to = '';
action.setRedirectURL(current);
current.update();
} else {
if (tableGR.next()) {
if (current.assignment_group != tableGR.assignment_group) {
current.assignment_group = '';
current.assigned_to = '';
current.assignment_group = tableGR.assignment_group;
} else {
gs.addInfoMessage('Assignment Group already correctly assigned.');
}
action.setRedirectURL(current);
current.update();
} else {
current.assignment_group = '';
gs.addInfoMessage('No Assignment Group.');
action.setRedirectURL(current);
}
}
}
gs.eventQueue('incident.assigned.to.group', current, 'Incident assigned to my group', '');
}
___________________________________________________________________________
SCRIPT INCLUDE
var AutoAssignGroupButton = Class.create();
AutoAssignGroupButton.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
var ci = this.getParameter('sysparm_ci');
var category = this.getParameter('sysparm_category');
var subcategory = this.getParameter('sysparm_subcategory');
var assignment_group = this.getParameter('sysparm_assignment_group');
var ciGR = new GlideRecord('cmdb_ci_business_app');
ciGR.addQuery('name', ci);
ciGR.query();
//CATEGORY AND SUBCATEGORY
var tableGR = new GlideRecord('dl_u_assignment');
tableGR.addQuery('category', category);
tableGR.addQuery('subcategory', subcategory);
tableGR.query();
current.setWorkflow(false);
if (ciGR.next()) {
if (ciGR.support_group != '' && assignment_group != ciGR.support_group) {
return ciGR.support_group;
} else if (assignment_group == ciGR.support_group) {
gs.addInfoMessage('Assignment Group already correctly assigned.');
} else {
if (tableGR.next()) {
if (assignment_group != tableGR.assignment_group) {
return tableGR.assignment_group;
} else {
gs.addInfoMessage('Assignment Group already correctly assigned.');
}
} else {
assignment_group = '';
gs.addInfoMessage('No Assignment Group.');
}
}
current.assigned_to = '';
action.setRedirectURL(current);
current.update();
} else {
if (tableGR.next()) {
//current.setWorkflow(false);
if (assignment_group != tableGR.assignment_group) {
current.assignment_group = '';
current.assigned_to = '';
assignment_group = tableGR.assignment_group;
} else {
gs.addInfoMessage('Assignment Group already correctly assigned.');
}
action.setRedirectURL(current);
current.update();
} else {
current.assignment_group = '';
gs.addInfoMessage('No Assignment Group.');
action.setRedirectURL(current);
}
}
},
type: 'AutoAssignGroupButton'
});