Display Catalog Item only in 2 months Available For Script

Hm10
Tera Contributor

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
    }
}

 

3 REPLIES 3

Mark Manders
Mega Patron

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

AshishKM
Kilo Patron
Kilo Patron

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

Vara_Pradeep
Tera Contributor

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