Catalog Item | Multiple Choice / Radio button | Dynamic choice

Sylvain12
Tera Contributor

Hello,

I'm working on a catalog item which has a Multiple Choice Variable with 2 choices:

- Current Year

- Next Year

 

I would like to make the choices dynamic, for example today the choices would be -2022 and -2023, and on 01/01/2023 choices would become -2023 and -2024.

I didn't find information on that, and I would like to know if this is possible to do ?

 

Thank you very much in advance for your feedback.

 

Kr,

Sylvain

 

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

If I understood correctly, you would like to show current year and next year value in drop down option in catalog item variable. If so please use below script :

 

Create On Load Catalog Client script:

 

var currentYear=new Date().getFullYear();
var nextYear=currentYear+1;
g_form.addOption('yourFieldNameHere', currentYear, currentYear,1);
g_form.addOption('yourFieldNameHere', nextYear, nextYear,1);

 Please mark answer as Correct or Helpful based on impact.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Hi Sylvain,

 

You could do this with a scheduled job that runs every year on 1/1 at 00:00:00 or something like that.  The job would run a script that changes the current record for this question on the question_choice table with the order = 1 ('Current Year', which is now last year) to inactive = true, updates the current record for this question with the order = 2 ('Next Year', which is now the current year) to order = 1, and creates a new record for this question, with the value of the previous record plus 1, or the year from a new GlideDateTime plus 1.  Sounds like fun.  Let me know if you get stuck getting the job/script to work. 

Hello Brad,

 

Thank you so much for your prompt reply ! I will try this and let you know.

Quick question: can scheduled job runs a catalog client script ?

 

Thanks !

No, this would be a server script.  Catalog Client scripts only run on the client/PC when the user is interacting with the record/Catalog Item.

Abhijit4
Mega Sage

If I understood correctly, you would like to show current year and next year value in drop down option in catalog item variable. If so please use below script :

 

Create On Load Catalog Client script:

 

var currentYear=new Date().getFullYear();
var nextYear=currentYear+1;
g_form.addOption('yourFieldNameHere', currentYear, currentYear,1);
g_form.addOption('yourFieldNameHere', nextYear, nextYear,1);

 Please mark answer as Correct or Helpful based on impact.

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP