Most of the times its much easier to work with encoded query instead of builing a query with GlideRecord API:
var query = "category=Hardware^priority=1";
var gr = new GlideRecord("incident");
gr.addEncodedQuery(query);
gr.query();
Encoded query is also useful for populating data to a GlideRecord object:
var query = "category=Hardware^priority=1";
gr = new GlideRecord('incident');
gr.applyEncodedQuery(query);
gr.insert();