- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 09:10 AM - edited 11-13-2024 09:11 AM
Hi ,
The OOB Business rule Populate Assignment Group based CI/SO is working fine the only condition not working is the ELSE it is executing but the assignemnt group is not populating. we tried with SYS ID and Name as well.
(function executeRule(current, previous /*null when async*/ ) { /* This business rule will get executed for incident/problem/change on insert and update, if Assignment Group is empty and CI/ServiceOffering changing from empty value. */ gs.log("<<<POP BR"); //!(current.sys_class_name + '' === 'change_request' && current.unauthorized == true) //!(current.sys_class_name + '' === 'change_request' && current.unauthorized == true) var assignmentGroupFieldName = ''; if (current.sys_class_name + '' == 'change_request') { assignmentGroupFieldName = 'assignment_group'; } else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') { if(current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') { assignmentGroupFieldName = 'support_group'; } else { assignmentGroupFieldName = "3f02ab9687359e10ab9c2fce8bbb355a"; } } if (!gs.nil(current.cmdb_ci) && current.cmdb_ci.changesFrom('')) { assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'ci') || assignmentGroupFieldName; current.assignment_group = current.cmdb_ci[assignmentGroupFieldName]; } if (gs.nil(current.assignment_group) && !gs.nil(current.service_offering) && current.service_offering.changesFrom('')) { assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'service_offering') || assignmentGroupFieldName; current.assignment_group = current.service_offering[assignmentGroupFieldName]; } })(current, previous); function populateAssignmentGroupFieldName(className, fieldName) { // Populate CI and Service Offering field names from properties that will be used to populate current task assignment group return GlideApplicationProperty.getValue('com.snc.' + className + '.' + fieldName + '_assignment_group.field_name'); } Thanks |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 06:50 AM
What is the overall requirement?
It looks like you want OOB behavior if x_moogs_incident_m_moogsoft_incident_id is not 'automation' - otherwise you want to set the assignment group to '3f02ab9687359e10ab9c2fce8bbb355a'?
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if(current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation')
{
assignmentGroupFieldName = 'support_group';
}
else
{
assignmentGroupFieldName = "3f02ab9687359e10ab9c2fce8bbb355a";
}
}
I am not familiar with the Moogsoft integration, but I would confirm that current.x_moogs_incident_m_moogsoft_incident_id is a valid field before attempting to process its value. You might also add some logging for while you're testing.
Something like this:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id')) {
// Log the value if the field is valid
gs.info('x_moogs_incident_m_moogsoft_incident_id is valid. Value: ' + current.x_moogs_incident_m_moogsoft_incident_id);
if (current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Do something
}
} else {
// Log that the field is not valid
gs.info('x_moogs_incident_m_moogsoft_incident_id is not a valid field on the current record.');
// Do something
}
}
After debugging, you can leverage short-circuit evaluation for cleaner code, if you like:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id') &&
current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Do something
}
}
Next, you should avoid using hard-coded sys_id. It is good practice to create a system property and store the sys_id there:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id') &&
current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Check the system property for the default assignment group sys_id
var defaultAssignmentGroupSysId = gs.getProperty('x_moogs_incident_m.default_assignment_group');
// Validate that the sys_id corresponds to an existing sys_user_group record
if (defaultAssignmentGroupSysId) {
var groupGR = new GlideRecord('sys_user_group');
if (groupGR.get(defaultAssignmentGroupSysId)) {
current.assignment_group = defaultAssignmentGroupSysId;
} else {
gs.info('Default assignment group sys_id from property x_moogs_incident_m.default_assignment_group is not valid.');
}
} else {
gs.info('System property x_moogs_incident_m.default_assignment_group is not set.');
}
}
}
Finally, you should be be aware that the first if statement below could set assignment group, so you should consider if you need to add gs.nil(current.assignment_group) && before !gs.nil(current.cmdb_ci) there.
if (!gs.nil(current.cmdb_ci) && current.cmdb_ci.changesFrom('')) {
assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'ci') || assignmentGroupFieldName;
current.assignment_group = current.cmdb_ci[assignmentGroupFieldName];
}
if (gs.nil(current.assignment_group) && !gs.nil(current.service_offering) && current.service_offering.changesFrom('')) {
assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'service_offering') || assignmentGroupFieldName;
current.assignment_group = current.service_offering[assignmentGroupFieldName];
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 09:25 AM
Hi @Nisha30 - In this BR, assignmentGroupFieldName is the name of the assignment group field. Are you trying to set the assignment group to a specific group?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 04:57 AM
yes i am trying to set to specific Group in else loop. The sys id is for that group.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 06:50 AM
What is the overall requirement?
It looks like you want OOB behavior if x_moogs_incident_m_moogsoft_incident_id is not 'automation' - otherwise you want to set the assignment group to '3f02ab9687359e10ab9c2fce8bbb355a'?
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if(current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation')
{
assignmentGroupFieldName = 'support_group';
}
else
{
assignmentGroupFieldName = "3f02ab9687359e10ab9c2fce8bbb355a";
}
}
I am not familiar with the Moogsoft integration, but I would confirm that current.x_moogs_incident_m_moogsoft_incident_id is a valid field before attempting to process its value. You might also add some logging for while you're testing.
Something like this:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id')) {
// Log the value if the field is valid
gs.info('x_moogs_incident_m_moogsoft_incident_id is valid. Value: ' + current.x_moogs_incident_m_moogsoft_incident_id);
if (current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Do something
}
} else {
// Log that the field is not valid
gs.info('x_moogs_incident_m_moogsoft_incident_id is not a valid field on the current record.');
// Do something
}
}
After debugging, you can leverage short-circuit evaluation for cleaner code, if you like:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id') &&
current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Do something
}
}
Next, you should avoid using hard-coded sys_id. It is good practice to create a system property and store the sys_id there:
var assignmentGroupFieldName = '';
if (current.sys_class_name + '' == 'change_request') {
assignmentGroupFieldName = 'assignment_group';
} else if (current.sys_class_name + '' == 'incident' || current.sys_class_name + '' == 'problem') {
if (current.isValidField('x_moogs_incident_m_moogsoft_incident_id') &&
current.x_moogs_incident_m_moogsoft_incident_id.toLowerCase() != 'automation') {
assignmentGroupFieldName = 'support_group';
} else {
// Check the system property for the default assignment group sys_id
var defaultAssignmentGroupSysId = gs.getProperty('x_moogs_incident_m.default_assignment_group');
// Validate that the sys_id corresponds to an existing sys_user_group record
if (defaultAssignmentGroupSysId) {
var groupGR = new GlideRecord('sys_user_group');
if (groupGR.get(defaultAssignmentGroupSysId)) {
current.assignment_group = defaultAssignmentGroupSysId;
} else {
gs.info('Default assignment group sys_id from property x_moogs_incident_m.default_assignment_group is not valid.');
}
} else {
gs.info('System property x_moogs_incident_m.default_assignment_group is not set.');
}
}
}
Finally, you should be be aware that the first if statement below could set assignment group, so you should consider if you need to add gs.nil(current.assignment_group) && before !gs.nil(current.cmdb_ci) there.
if (!gs.nil(current.cmdb_ci) && current.cmdb_ci.changesFrom('')) {
assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'ci') || assignmentGroupFieldName;
current.assignment_group = current.cmdb_ci[assignmentGroupFieldName];
}
if (gs.nil(current.assignment_group) && !gs.nil(current.service_offering) && current.service_offering.changesFrom('')) {
assignmentGroupFieldName = populateAssignmentGroupFieldName(current.sys_class_name + '', 'service_offering') || assignmentGroupFieldName;
current.assignment_group = current.service_offering[assignmentGroupFieldName];
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 07:07 AM
You are correct.
I have applied all logs in each loop and it seems all logs are coming okay the only thing is even though i get logs for that loop , it does not set the assignment group to the one i need (mentioned as SYS ID).
Might be i am missing syntax how to set or not sure. The field is correct thats an OOB one came with Moogsoft.
Thanks