Is it possible in the Item form to compute a field directly while saving the Item, or alternatively via a trigger to the Action Processor?
Here’s the scenario:
We have two fields:
Item End Date
Item Notification Days
We’d like to automatically calculate and keep updated a third field:
Item Notification Date = Item End Date - Item Notification Days
The Item Notification Date should be a read-only field, managed entirely by the system.
Has anyone implemented something similar or found a reliable approach to achieve this?
Thanks in advance!
Page 1 / 1
Not sure how you would be able to use Action Processor, because you’re not taking an action on an event. Here’s how I would do it via ETM at a high level (since I’m not great at building data mappers, but someone smarter than me should be able to figure the datamappers/channel out.)
Export all existing Items via the Data Management Worksheets
Create a separate CSV with just the shortCode of all of the items (Column A), then add the values I wanted for Item End Date (Column , Item Notification Days (Column C) and then in the fourth column, the value of Column B - Column C, which would give you the value you want for Item Notification Date (Column D).
Create a new ETM channel to Update the Items, where it uses Column A as the Record To Update, then updates that item with the data from Column B, Column C and Column D.
Now you should have it all working for all existing items. Now you could just use the same ETM channel you created in the previous steps going forward for any updates and manually run it on a regular basis so it updates any Items that have changed and adds the values for any new Items that have been added.
Automating this might be tricky tho, as you’d need to find a way to automate getting the existing Item shortCodes and I’m not sure you can automate the Data Management Worksheets. But if you can find a way to automate pulling the Item ShortCodes, then you could automate the ETM channel by scheduling a PowerShell script via Windows Task Manager (or whatever job scheduling tool you want to use) to run a powershell script to call that ETM channel and pass the CSV of values.
You could try a scheduled ETM channel for this purpose. This isnt a fully formed solution but it might get you started.
User one of the userFieldFlags for ‘Notification Calculated’ (unless you are confident userFieldChar === null returns the correct information. I am not at the time of typing) and use the following search:
Note that you are limited in the number of assets you can pull this way so your initial runs might need to be close together to get through your database.
You can build an array of calculated values as such:
var days = 60; var millisecondsInADay = 24 * 60 * 60 * 1000; var offset = days * millisecondsInADay;
var output = variables._items.map(function(current) { var expiryTimestamp = Number(current.expiryDate); var noticeTimestamp = expiryTimestamp - offset;
Feed this into an iterator expression to run a mapper per asset carrying out the following actions:
Check the userFieldFlag to true to exclude from future imports,
Fill in the notification date (you could also use a userFieldDate for this if you wanted to make it searchable via the ETM for sending the notifications or creating events from the dates).
(Optional) Add movement to signify when the date was calculated.
(Optional) Add to your regular import from AD (or similar system) to recalculate on a regular basis if this expiry date is likely to change.
I hope this gives you some food for thought. Let us know what you end up doing.