Auto Submit catalog item based on a date field on a table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 01:56 PM
Hi All,
I have a requirement to auto-submit a catalog item based on 'End Date' field on Software Entitlement (alm_license) form. Whenever any record on the table has 'End date' less than 90 days I need to submit a catalog item to support team ( I'm aware that catalog item can be submitted using cart API) but I'm not sure how to set the trigger condition for my scenario. I may need to check the 'End date' values on the table every day on all the records and then submit the catalog.
Could someone help how to check and compare 'End date' with the current date and set the trigger condition please.
Thanks,
RJ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:07 PM
Use a flow or a scheduled job that queries for all alm_license records who's end date is 90 days from now. You can use a relative query to do this. Something like
end_dateRELATIVEGT@dayofweek@ahead@90^end_dateRELATIVELT@dayofweek@ahead@91
The above will bracket the date so that you will only get the one day. Then you can process those checking to make sure there is not already an open record and if not order one. This is assuming that the end date will always be set initially to something more than 90 days in the future. If new records in the alm_license table will have an end date sooner than 90 days you will just have to query for end date relative to before 90 days from now and check them all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:08 PM - edited 04-11-2023 02:08 PM
Automatically submit a catalog item based on the "End Date" field on the Software Entitlement (alm_license) form is to use a scheduled job that runs every day to check the "End Date" values on the table and submit the catalog item if the end date is less than 90 days away.
Here are the steps to implement this solution:
- Create a new scheduled job:
- Navigate to "System Scheduler > Scheduled Jobs" in the ServiceNow instance.
- Click on "New" to create a new scheduled job.
- Give your job a name and select a suitable frequency for it to run (e.g. daily).
- In the "Advanced" tab, add a new script that checks the "End Date" values on the alm_license table and submits the catalog item if the end date is less than 90 days away.
- Check the "End Date" values on the alm_license table:
- In the script, use a GlideRecord query to retrieve all the records from the alm_license table where the "End Date" field is less than 90 days away from the current date.
- Here's an example script:
var licenseGr = new GlideRecord('alm_license'); licenseGr.addQuery('end_date', '<=', gs.daysAgo(90)); licenseGr.query(); while (licenseGr.next()) { // submit catalog item using cart API var cartApi = new sn_sc.CartJS(); var cartItem = cartApi.addItem('catalog_item_sys_id', 1); cartApi.submit(); }
Replace "catalog_item_sys_id" with the sys_id of the catalog item you want to submit.
This solution uses a scheduled job to check the "End Date" values on the alm_license table and submit the catalog item if the end date is less than 90 days away.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 03:25 AM
Hi Duggi,
Thanks for your response.
I have tried the script you have shared, but it is not executing for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2023 06:54 AM
@Community Alums the above code snippet was a sample, did you update the "catalog_item_sys_id, the catalog has any mandatory variable, did you try to pass the variables through the script?
- Can you confirm if there were any errors encountered?
- Have you verified that the "End_date" field is populated with data?
- I suggest adding logging within the while loop instead of immediately making a request.
catalog_item_sys_id