Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Javascript for reference qualifier on date field

mjt
Kilo Explorer

Hi,

 I'm currently struggling with getting a reference qualifier to work with JavaScript and hoping someone might be able to help.  I have a table of sporting fixtures that includes fields for sport, country, start date and tournament.  I would like to prompt the user for a country and date on the catalogue item and show a list of tournaments for them to select from (sport will be hard coded to Tennis and ruleset to Women). I have added the country and date variables to the catalogue item definition.  For the tournament variable, so far I have this working..

javascript:'u_sport=Tennis^u_ruleset=Women^u_country='+current.variables.country

but I'm not sure how to add the date condition to this.  I have run a filter on the table and retrieved this query but not sure how to convert the string.

u_sport=Tennis^u_ruleset=Women^u_country=d44c63c037a417403842138943990e2c^start_dateON2019-03-13@javascript:gs.dateGenerate('2019-03-13','start')@javascript:gs.dateGenerate('2019-03-13','end')

The fixture start date in the table is stored as a datetime but I only need to prompt the user for a date.

Please would someone be able to assist me this, I would be very grateful.

Mike.

 

 

3 REPLIES 3

paulmorris
Giga Sage

Try this:

u_sport=Tennis^u_ruleset=Women^u_country=d44c63c037a417403842138943990e2c^start_dateON2019-03-13@javascript:gs.dateGenerate('2019-03-13','start')@javascript:gs.dateGenerate(current.variables.end_date,'end')


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Thanks Paul, tried this but still not working.  I think the first date needs to be variable as well.  Also because it's passed as a string, I think it needs to exit out of the string before the variables.  Have tried this also but can't get it to work...

 

javascript:'u_sport=Tennis^u_ruleset=Women^u_country='current.variables.country+'^start_dateON@javascript:gs.dateGenerate(''+current.variables.fixture_date+'','start')@javascript:gs.dateGenerate(''+current.variables.fixture_date+'','end')'

matthew_magee1
Giga Guru

Did you get this to work? I'm looking to do something similar-