Display of Record producer form portal in particular month using user criteria

sony8
Tera Contributor

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? 

 

 

1 ACCEPTED SOLUTION

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();

    }

 

 

VishalBirajdar7_0-1694614771101.png

 

 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

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

12 REPLIES 12

Vishal Birajdar
Giga Sage

@sony8 

 

Why not to use scheduled job to make record produce "Active=true" if month is august and deactivate it for all other months.

Just a thought..!!

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

@Vishal Birajdar could you please share more info i will try it??

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();

    }

 

 

VishalBirajdar7_0-1694614771101.png

 

 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

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ankur Bawiskar
Tera Patron
Tera Patron

@sony8 

you can use user criteria with script and use advanced script

answer = new GlideDateTime().getMonthLocalTime() == 8;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

I have added above script in user criteria. I am able to see record producer now also. As i mentioned it should be visible only in month August. This month is September if i reload my portal under category i am able to see the lookup request.

am i testing in wrong way??