Use property file in Encoded query date filter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 12:27 AM
Hello Experts,
I have a requirement to use property file for Date Start and End in encoded query script of UI Action. The reason being the Date would be dynamic values.
I have create two date format type properties and written the script as below, but it doesnt seem to query the date from the properties within encoded query.
Can you please help me with where I am wrong with the query code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2023 01:21 AM
Hi, I suspect there is a little misunderstanding around sys_properties, as they are accessed in this format.
var myResult = gs.getProperty('the.property.name');
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideSystemAPI#r_GS-ge...
It is also nearly always easier (most likely to work) if you build your query string, assign it to a variable and then consume it. Something like this should work (untested).
var myStartDate = gs.getProperty('asset.warranty.start');
var myEndDate = gs.getProperty('asset.warranty.end');
var myQuery = "warranty_expirationBETWEENjavascript:gs.dateGenerate('" + myStartDate + "','start')@javascript:gs.dateGenerate('" + myEndDate + "','end')"
var updateAsset = new GlideRecord("alm_hardware");
updateAsset.addEncodedQuery(myQuery);
updateAsset.query();
while (updateAsset.next()) {
updateAsset.project_deployment = current.sys_id;
updateAsset.update();
}