- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 09:19 PM
I have the field u_assignment_history of type List on the incident table. I have a requirement to write a Business Rule on the incident table on insert and update that whenever the field assignment_group (reference to sys_user_group table) changes, I need to insert into the u_assignment_history list the previous and the current group. Basically the goal of the Business rule is to show all groups that were the assignment group on the current incident. How can I achieve that?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 10:11 PM
Hello Alon,
1.You can write before business rule with below condition.
2. Script
(function executeRule(current, previous /*null when async*/ ) {
var agHis = current.u_assignment_group_history.toString();
if (agHis) {
current.u_assignment_group_history = current.u_assignment_group_history.toString() + ',' + current.assignment_group.toString();
} else {
/* Set assignment group history for first time */
current.u_assignment_group_history = current.assignment_group.toString();
}
})(current, previous);
Also its better to set assignment group history field to be read-only.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 09:33 PM
Hello @Alon Grod ,
1. You can achieve this by writing before update business rules on the incidents table. use the following script.
Script:
(function executeRule(current, previous /*null when async*/) {
if(current.u_assignment_history.toString().includes(previous.assignment_group.toString()))
current.u_assignment_history=current.u_assignment_history.toString()+','+current.assignment_group.toString();
else
current.u_assignment_history=current.u_assignment_history.toString()+','+previous.assignment_group.toString()+','+current.assignment_group.toString();
// Add your code here
})(current, previous);
2. Another way to achieve this is to write on change client script on assignment group.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var temp=g_form.getValue('u_assignment_history').toString+','+newValue;
g_form.setValue('u_assignment_history',temp);
//Type appropriate comment here, and begin script below
}
Please mark this as the correct answer and helpful if it is resolved, or mark this helpful if this helps you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 10:11 PM
Hello Alon,
1.You can write before business rule with below condition.
2. Script
(function executeRule(current, previous /*null when async*/ ) {
var agHis = current.u_assignment_group_history.toString();
if (agHis) {
current.u_assignment_group_history = current.u_assignment_group_history.toString() + ',' + current.assignment_group.toString();
} else {
/* Set assignment group history for first time */
current.u_assignment_group_history = current.assignment_group.toString();
}
})(current, previous);
Also its better to set assignment group history field to be read-only.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates