I want to use the filter conditions set by the user in a list as query conditions within the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I'm considering a process to export all records stored in a table in bulk, based on filter conditions set by the user in a list.
I want to specify the same query conditions as the manually set filter conditions during the export, but it doesn't work correctly if the filter conditions contain "javascript:~".
The copied query: "caller_id=javascript:gs.getUserID()^active=true^universal_requestISEMPTY"
The script retrieves the data as shown below, but executing addEncodedQuery with a condition including "javascript:~" did not work.
*The query condition is set within test_ajax.
var query = "";
var list = GlideList2.get('incident');
query = list.getQuery();
alert(query);
var ga = new GlideAjax('test_ajax');
ga.addParam('sysparm_name', 'start');
ga.addParam('sysparm_query', query);
ga.getXMLAnswer(function(a) {
alert(a);
});Does anyone know a better way?
Although it's set to export in bulk, in reality, it's exporting in batches of 1000 items.
A waiting time is also included to avoid high load.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @bonsai ,
you can try this on the server side within your Script Include. Use a simple regular expression to replace : with a standard colon (:) before passing the query to your GlideRecord object.
start: function() {
var rawQuery = this.getParameter('sysparm_query');
var cleanQuery = rawQuery.replace(/:/g, ':');
var gr = new GlideRecord('incident');
gr.addEncodedQuery(cleanQuery);
gr.query();
// ... your 1000-item batching and export logic ...
return "Export batch complete";
}
also you don't need to change anything in your Client Script passing the encoded string via ga.addParam() is correct.
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Executing `[var cleanQuery = rawQuery.replace(/:/g, ':');]` results in an error.
The actual string stored in `rawQuery` was "caller_id=javascript:gs.getUserID()^active=true^universal_requestISEMPTY".