Composite to Add Interval (Working Days)

I’m looking for a solution which will enable us to “Add interval…” and “Subtract interval…” of ‘Working days’ within a composite.
I would like a composite to calculate a target completion date of 10 working days.
Does anyone have a suggestion how this can be achieved?

Hi Karl,

That isn’t currently possible in a composite.

The only thing I could suggest would be a Code Studio plugin.


Hi Karl,

Within Code Studio you have a function called mats.​is_working_day(), you can loop through until you get to X working days ahead and return the date.


I’m just about to do something like this myself. I’ll put it together and then share with you Karl.

Hi Karl, Do you need this purely as a display field or do you need to save the value off somewhere?

I’ve wrote myself an event action as I need to save and work with dynamic values. If you only need a display field and it’s always 10 days I can do you a fragment callback instead as it will be simpler for you.

Hi Both,
Thanks for your help.
Sean, i to would need to save the value, anything you could share would be helpful.

Ok Karl, please find steps below. If you have any questions or run into difficulties then get in touch with me directly and I’ll help you out. or 0330 333 6100.

  1. Make sure you have a date and time field configured to save the calculated date into.
  2. Open code studio and click the ‘References’ tab and then the ‘Add Reference’ button. You can name it anything you want but I’ve named mine ‘field_case_deadline_date’. Set the Type to ‘Field Path’ and then select the same base object that you will use for your rule and select the field you’ve created to save the date. Save/Create the reference.
  3. Click on Processors > Event Actions in the left hand pane and then ‘Add new’.
  4. Name it anything you want, then click onto the parameters tab and add parameters like so:

  1. Click the green ‘Create’ button and you should then have access to the Code tab once it’s refreshed.

  2. Copy the following code into the window and press the ‘Publish’ button.

     // Fetch record that event has been triggered against
     const caseRecord = mats.record(params.record_id);
     // Fetch working days parameter value
     let workingDays = parseInt(params.custom.working_days);
     // Check that working days is actually a number
     if (isNaN(workingDays))
     let system_notification = new mats.core.system_notification();
     system_notification.show_notification('error', 'Working days not a 
     } else
      // Set variables accounting for whether adding or subtracting working days
     const increment = (workingDays < 0) ? -1 : 1;
     const targetDays = workingDays * increment;
     //  Fetch start date parameter value
     let targetDate = new Date(params.custom.start_date);
     // Set up loop to run until the number of specified working days has elapsed
     let i = 1;
     while (i <= targetDays)
     		// Set current working date to current date +/- 1
     		targetDate.setDate(targetDate.getDate() + increment)
     		// Check if working date is a working day and if so increment loop counter
     		if (mats.is_working_day(targetDate.toISOString().substring(0, 10)))
     // Once loop exits format final date for updating record
     const targetDateString = targetDate.toISOString().substring(0, 10);
     // Log to detective the date being saved
     mats.log("Setting target date to: " + targetDateString);
     // Save target/deadline date to object 
  3. You’ll then need to add yourself a rule to trigger your event action. In my case I need my trigger to be quite dynamic as there’s multiple processes that can knock on a deadline change so I’m monitoring fields however you may be able to have something simple like a record has been created etc. The response will look like this:

I can’t post a second screenshot as I’m a ‘new user’. In the response select the Action as ‘Code Studio Event Action’ and then select the one you’ve just added, parameters should be self explanatory.

If in your case it is always 10 working days then you can tick the Fixed Value checkbox and just enter 10 rather than linking it to a field.

Hopefully this gives you enough to get something working, if you run into any issues drop me a line.

1 Like

Hi Sean,
Thanks very much, worked a treat.