- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 12:16 PM
I have this business rule that I would like to only run the first time a team member changes the State from "New" to some other state...any thoughts on how I can modify this to make it so it doesn't run if they go from State to State as long as they don't go back to New?
Name: Calculate Duration Given a Schedule
Table Name: Catalog Task [sc_task]
Run at Server
When to run: Before
Insert Checked
Update Checked
Advanced Condition: current.state.changes() && (current.state != 1)
Script:
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
gs.include('DurationCalculator');
var time_elapsed = executeSample(current.sys_created_on,current.u_task_activated_date);
var workday = 36000;
var time_elapsed_1 = time_elapsed/workday;
time_elapsed = time_elapsed_1.toFixed(1);
current.u_time_to_task_activation = time_elapsed;
}
function executeSample(sDate,eDate) {
// First we need a DurationCalculator object.
var dc = new global.DurationCalculator();
// The above sample is useful in limited cases. We almost always want to
// use some schedule in a duration computation, let's load a schedule.
addSchedule(dc);
// Compute a duration using the schedule. The schedule
// specifies a nine hour work day. The output of this is 36000 seconds, or
// a ten hour span.
dur = dc.calcScheduleDuration(sDate,eDate);
gs.info("calcScheduleDuration with schedule with Dynamic Values: " + dur);
return dur;
}
function addSchedule(durationCalculator) {
// Load the "M-F Workday" schedule into our duration calculator.
var scheduleName = "M-F Workday";
var grSched = new GlideRecord('cmn_schedule');
grSched.addQuery('name', scheduleName);
grSched.query();
if (!grSched.next()) {
gs.log('*** Could not find schedule "' + scheduleName + '"');
return;
}
durationCalculator.setSchedule(grSched.getUniqueValue());
}
Is it something I can put up in the Condition? Or do I need to wrap the "u_time_to_task_activation" field in some sort of script that only allows it to be updated if it is blank?
thanks in advance,
Richelle
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 12:23 PM
You could set the condition to (changes from new && custom_field is false) and create a hidden field custom_field that stores true/false. The first time it changes, change the value to true. Then if someone changes it to new -> in progress it wont trigger this BR.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 12:23 PM
You could set the condition to (changes from new && custom_field is false) and create a hidden field custom_field that stores true/false. The first time it changes, change the value to true. Then if someone changes it to new -> in progress it wont trigger this BR.