I need to exclude a business rule if submit from a specific table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 03:03 AM
Hello All
I have a field called "Time Worked Category" in the Task table that I automatically cascade to the Task Time Worked entry when submitting.
However, I need this script to not cascade is the entry is created directly in the Task Time Worked table.
How can I exclude my business rule to run and ignore the value in the Task form if the user inputs directly the Time into a new Task Time Worked entry ?
Here is the code I have :
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var taskID = current.task.sys_id;
var workCategory = current.task.u_time_worked_category;
var claimOvertime = current.task.u_claim_overtime;
var actualTime = current.task.u_actual_start_time;
if ((workCategory != '') && (workCategory != 'operational_work')){
current.u_work_category = workCategory;
}
current.u_claim_overtime = claimOvertime;
current.u_actual_time_creation = actualTime;
if ((claimOvertime == true) || (current.u_claim_overtime == true)) {
current.u_overtime_status == 'Requested';
} else {
current.u_overtime_status == '';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 03:11 AM
simply check if the value is present or not on Task Time Worked table. if not then set it via script
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
var taskID = current.task.sys_id;
var workCategory;
if(current.u_work_category == '')
workCategory = current.task.u_time_worked_category;
else
workCategory = current.u_work_category;
if(current.u_work_category == '')
var claimOvertime = current.task.u_claim_overtime;
var actualTime = current.task.u_actual_start_time;
if ((workCategory != '') && (workCategory != 'operational_work')){
current.u_work_category = workCategory;
}
current.u_claim_overtime = claimOvertime;
current.u_actual_time_creation = actualTime;
if ((claimOvertime == true) || (current.u_claim_overtime == true)) {
current.u_overtime_status == 'Requested';
} else {
current.u_overtime_status == '';
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 03:15 AM
Hello Ankur,
The issue I have is that the Time Worked Category in the task table is never set to None, it got a default value.
So I'm trying to see if I can do this via another way.
I'm suspecting that I'll not have the choice to create a new field in Task Time Worked, in which one I copy the value from the Task, and if this new field is not none, override the category of the time worked entry with this value.
What do you think ?