- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 06:52 AM
In our Service Center, we have a Select Box variable with hard-coded dates.
Here is the variable definition. It is a Select Box with Question Choices. That is where the dates are hard-coded.
We want to remove dates that are 35 days or less. My idea is to set up a catalog client script, iterate through the question choices (like an array), convert each string to a date and compare with today's date. If that date is equal to or less than 35 days, then I could remove that date such as this...
g_form.removeOption('field_name','choice_value');
What would be the code to iterate through the question choices of a Select Box variable?
Solved! Go to Solution.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 07:11 AM
There's two options you can try that will potentially let you do it client side.
Otherwise, if that does NOT work, Option 3...you can always use GlideAjax to access a server script where you can query the "Question Choice" table, and return the list of values you could then loop thru and removeOption.
Let me know if that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 07:11 AM
There's two options you can try that will potentially let you do it client side.
Otherwise, if that does NOT work, Option 3...you can always use GlideAjax to access a server script where you can query the "Question Choice" table, and return the list of values you could then loop thru and removeOption.
Let me know if that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 07:12 AM
Hi,
Probably it would be better to run an Ajax call to a client callable script include and use GlideDate time to compare the dates and identify the ones. Then whatever values the script include returns you can remove the options.
If you really want to do all on the client side, you can get the options with something like:
var options = g_form.getElement('meeting_dates').options;
var compareDate = (24*60*60*1000*35); //35Days in ms
for(var i=0; i< options.length; i++) {
var optionDate = new Date(options.value);//Adjust to the correct format here
if(optionDate < compareDate )
g_form.removeOption('meeting_dates', options.value);
}
Haven't tested the code but should work.
I hope it helps!
Pedro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 07:13 AM
Hi,
If you don't mind explaining, is there a reason you're using hardcoded dates within this variable, on this catalog item?
I would envision a different way to approach this than the technical debt involved here.
But, if you must use this method, then you'd have to utilize something like an onLoad client script to use GlideAjax to communicate with the server and the related table, retrieve the values, evaluate if 35 days or less and then send back an array of the selections to then remove from the select-box.
Please mark reply as Helpful, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 07:36 AM
Does the GlideAjax wait until the rest of the form loads? Reason I ask is I'm using this code in my catalog client script, and it is returning 0 (no options).
function onLoad() {
var sel = g_form.getControl("meeting_dates").options;
alert(sel.length);
g_form.getReference("meeting_dates", getReqForDate);
}
function getReqForDate(reqFor) {
var sel = g_form.getControl("meeting_dates").options;
alert(sel.length);
}
I'm thinking because the client script runs before the question choices load?
Also Allen if you know of a better way, a best practice to accomplish the hard-coded dates please share. The business owner wants to keep these values internal without setting up an external table.