- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 02:20 AM
I am having some issues getting date calculations and lookups to work as expected in Flow Designer.
I have a requirement to empty a users shopping cart (basket) if they have not checked out within a given number of days. I can do this quite simply in flow designer, having a daily flow which checks for records in the sc_cart_item table where last update was x days ago, and if any were found then delete them.
However, for flexibility and ease, it was suggested that we have a property that defines the number of days after which the cart should be emptied, and use this in the flow.
I have created an action which looks up the property to find the number of days, converts this into milliseconds, and then deducts that from the current time (see script below).
(function execute(inputs, outputs) {
var cartEmpty = gs.getProperty("basket.empty.time");//get property for number of days
var nowGDT = new GlideDateTime();//get now
var cartTime = (cartEmpty*86400000);//convert to milliseconds
nowGDT.add(-cartTime);
outputs.empty = nowGDT;
})(inputs, outputs);
When I test this script from the action, it works fine, calculating exactly the date expected.
However, when I try to use this in a flow, using the date output from the custom action, and looking for records that were updated before the calculated date to then delete the records in the sc_cart_item table, it does not work.
The dates seem to be being passed correctly, but it does not detect the items that it should from the lookup, and therefore does not remove them.
I have tried doing lookups using created date and updated date, and used before, at or before, relative and all do not provide the desired outcome.
Any ideas?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 03:49 AM
Hi,
Can you try calling the system property in the filter condition itself using javascript:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 03:38 AM
Strange.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 03:40 AM
I agree 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 03:49 AM
Hi,
Can you try calling the system property in the filter condition itself using javascript:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 04:28 AM
I have added a script to the conditions instead of using the custom action and pill from that action. This seems to work as desired now.
Script added was as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 04:42 AM
Glad to help.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader