- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 01:51 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 05:36 AM
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.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 04:39 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 05:06 AM
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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 05:15 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 05:36 AM
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.
Regards,
Abhijit
ServiceNow MVP