Business rule to make assigment group empty when first service field doesnt have an assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 01:08 AM
Hello
I need help in writing a business rule code that will perform the function - If the first service selected on the 'some fields' field doesn't have an assignment group associated to it, the 'Assignment Group' field value should be cleared"
for other functionality, I already have a business rule written and I don't know what code to add here so that the rest will still work properly.
(function executeRule(current, previous /*null when async*/ ) {
var services = current.u_upmx_services.toString().split(',');
var firstService = services[0];
var workflowView = current.u_workflow_view.toString();
var mockGR = new GlideRecord('tsp4_demand');
mockGR.initialize();
mockGR.u_upmx_services = firstService;
mockGR.u_workflow_view = workflowView;
var new_assignment_group = new SAG_ITBM_AssignmentRule().getRules(mockGR);
if (new_assignment_group != -1) {
current.setValue("assignment_group", new_assignment_group);
current.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 01:43 AM
Hi,
You can add an else condition here.
(function executeRule(current, previous /*null when async*/ ) {
var services = current.u_upmx_services.toString().split(',');
var firstService = services[0];
var workflowView = current.u_workflow_view.toString();
var mockGR = new GlideRecord('tsp4_demand');
mockGR.initialize();
mockGR.u_upmx_services = firstService;
mockGR.u_workflow_view = workflowView;
var new_assignment_group = new SAG_ITBM_AssignmentRule().getRules(mockGR);
if (new_assignment_group != -1) {
current.setValue("assignment_group", new_assignment_group);
current.update();
}
else{
current.setValue("assignment_group", '');
current.update();
}
})(current, previous);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 03:02 AM
unfortunately, now it works so that only if Affected UPM-X Service(s) are selected without an assigned group, the assignment group remains empty. I'm wondering about the code that will work on the principle - if the first group in Affected UPM-X Service(s is not assigned group assignment then the assignment group field will be left blank even if you select others with an assignment group. Because now, unfortunately, if we choose at least one of the assigned assignment group, it immediately downloads data from this place, even if it is, for example, in the 3rd position
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 11:49 PM
Do you have any idea how to make it so that only the first choice is taken into account?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2022 11:57 PM - edited 12-18-2022 11:58 PM
@New user1212 Please change code as below
(function executeRule(current, previous /*null when async*/ ) {
var services = current.u_upmx_services.toString().split(',');
var firstService = services[0];
var workflowView = current.u_workflow_view.toString();
var mockGR = new GlideRecord('tsp4_demand');
mockGR.initialize();
mockGR.u_upmx_services = firstService;
mockGR.u_workflow_view = workflowView;
var new_assignment_group = new SAG_ITBM_AssignmentRule().getRules(mockGR);
if (services.indexOf(new_assignment_group) != -1) {
current.setValue("assignment_group", new_assignment_group);
}
else{
current.setValue("assignment_group", '');
}
current.update();
})(current, previous);
I assumed if the new assignment group is not present in services, then only add assignment group else clear it.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
