Trying to query a string, with date as value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 07:12 AM
I am trying query a table i have which has date as a string. I am trying to use a value on a form to reference and get the correct date associated to a name
u_resource_start_date is a string in a table i have stored. However, u_start_date is a date field so when i run the business rule it is not grabbing the correct date and always defaults to a date.
Background- i have a table with projects(u_project) and i am getting the project on the form by using a gliderecord with the u_demand. I get the correct project, but each project has a different start date hence a separate record for a different start date. So I want to use the date on the form that is a date field and use that to query the table for the date which is a string
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord ('u_adam_resource_test');
gr.addQuery('u_project', current.getDisplayValue('u_demand_id') );
gr.addQuery('u_resource_start_date', current.getValue('u_start_date') );
gr.query();
if(gr.next()){
current.setDisplayValue('u_form_test', gr.u_project);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 07:29 AM
You should try converting the u_start_date to string(same format as u_resource_start_date) and then do a glide record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 07:33 AM
Sounds like the start date of a project should be a glide_date. Maybe u_resource_start_date could instead be made a glide_date as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 07:32 AM
Are you querying for the same date format as you're using in your String field? e.g., both date and String show as "2017-05-30"?
When you do a gs.addInfoMessage on current.getValue("u_date"), what do you see compared to the String value you're searching for?
I just did a trivial test that worked as expected. I saved an Incident record w/ a populated glide_date field "u_date". I then put that same date (in the same date format!) in the Short description of two other Incidents (String field). I then grabbed my first record w/ a GlideRecord script, variable name "gr1".
Then I queried incident where short_description was gr1.getValue("u_date"), and I got the two records I wanted.
Here's my test script:
doit();
function doit() {
var gr1 = new GlideRecord('incident');
gr1.get("11b63e294f47f2008a959a211310c74a");
gs.print("date I'm querying for is: " + gr1.getValue("u_date"));
var gr2 = new GlideRecord('incident');
gr2.addQuery("short_description", gr1.getValue("u_date"));
gr2.query();
while (gr2.next())
gs.print("got one!");
}