Display Catalog Item only in 2 months Available For Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:08 AM
I want this Catalog Item to be visible only in 2 months in the year.
This is Available For Script in this item.
But this is not hiding the script
getAnswer()
function getAnswer() {
var currentTime = new GlideDateTime();
var currentMonth = currentTime.getMonth(); //
if ((currentMonth == 5) || (currentMonth == 9)) {
return true
} else {
return false
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:28 AM
Why not create a flow or scheduled job triggering on the 1st of the month it needs to be there and the first of the month to have it 'removed' and set the 'active' flag to true/false to show or not show?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 06:58 AM
Hi @Hm10 ,
And where you exactly writing this code. Share the screen shot of that object.
Better to update this catalog item as active = true/false based on required months.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 06:56 AM
Hi @Hm10 ,
The reason for your scripted user criteria not working might be associated to cache issue.
You can clear the cache by typing cache.do in the application navigator and clear it there, then you should be able to achieve your requirement, the scripted User Criteria should work.
But here I suggest you to go for the scheduled Job approach as mentioned by @Mark Manders .
The reason for my suggestion is : The script in the User Criteria will be evaluated as long as this User Criteria is not cached. Once the User Criteria is cached, it will always return the first value the script returned and will not evaluate the script anymore unless the cache is cleared. or the User Criteria record is changed.
Check out the support article https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0790108