- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:24 AM - edited 09-13-2023 06:25 AM
Hi
I have below requirement.
there is Lookup request record producer on the portal.
I want the record producer to be visible only in month of August. other than August i don't want to see the Lookup request on portal.
for this i have created user criteria and add to Lookup request Available for.
var gdt = new GlideDateTime();
gdt.addMonthsLocalTime(8);
gs.info(gdt.getDate());
Not understanding why my user criteria not working?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 07:21 AM
Hi @sony8
//I have done it for Month September
Scheduled Job
Name : Activate Record producer if Month is September
Run : Monthly
Day : 1
Time : 00:00:00
Script :
var date = new GlideDateTime();
var grRP = new GlideRecord('sc_cat_item_producer');
grRP.addQuery('sys_id', '080fa5079777c5101780db24a253af97');
grRP.query();
if (grRP.next()) {
if (date.getMonthUTC() == 9) {
grRP.active = true;
} else {
grRP.active = false;
}
grRP.update();
}
Note : Do not use hard coded value for sys_id (I have used just for testing here)
You can use Conditional option if you want to run scheduled job on specific condition
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:29 AM
Hi @sony8
The user criteria that you have created is not working because you are using the addMonthsLocalTime() function to get the date in August.
But I think the Available for user criteria uses the system date to determine whether or not the record producer is visible.
you can try using the sysdate() function to get the system date.
The following code will create a user criteria that will make the record producer visible only in the month of August:
var userCriteria = new UserCriteria();
userCriteria.setOperation('equal');
userCriteria.setField('sysdate');
userCriteria.setValue(new GlideDate('08/01/2023'));
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:35 AM
@Tushar i have added same code in my criteria. Same issue. this user criteria is not working..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:46 AM - edited 09-13-2023 06:47 AM
Hi,
answer=monthCall();
function monthCall(){
var monthis=new GlideDateTime().getMonth();
if(monthis=='8')
{
return true;
}
else
{return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2023 06:58 AM
@Jaspal Singh Not working