Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How add a filter in server script with query

i'm new in servicenow and I have to add this filter "document_id.number STARTS WITH BKNG" as a query, how can i do in servicenow?

this is my code:

// only show 30 in header menu dropdown
var max = 30;

var t = data;
t.items = [];
t.count = 0;

var u = getMyApprovals();

// use record watchers to tell header when to update dropdown counts
t.record_watchers = [];
t.record_watchers.push({'table':'sysapproval_approver','filter':'approverIN' + u.toString() + '^state=requested'});

var z = new GlideRecord('sysapproval_approver');
z.addQuery("approver", u);
z.addQuery("state", "requested");
z.addQuery("document_id.number", "STARTSWITH", "BKNG")
z.orderByDesc('sys_updated_on');
z.setLimit(max);
z.query();

var link = {};
link.title = gs.getMessage('View all approvals');
link.type = 'link';
link.href = '?id=approvals';
link.items = [];
t.items.push(link);

while (z.next()) {
  var a = {};
  var rec = getRecordBeingApproved(z);
    if (!rec.isValidRecord())  // nothing being approved - hmmm
        continue;
    
  a.short_description = rec.short_description + "";
  if (rec.getRecordClassName() == "sc_request") {
    var items = new GlideRecord("sc_req_item");
    items.addQuery("request", rec.getUniqueValue());
    items.query();
    if (items.getRowCount() > 1)
      a.short_description = items.getRowCount() + " requested items";
    else if (items.getRowCount() == 1) {
      items.next();
      a.short_description = items.getValue("short_description");
    }
  }
  $sp.getRecordValues(a, z, 'sys_id,sys_updated_on');
  a.number = rec.getDisplayValue();
  a.__table = z.getRecordClassName();
  a.type = 'approval';
  t.items.push(a);
  t.count++;
}

function getRecordBeingApproved(gr) {
  if (!gr.sysapproval.nil())
    return gr.sysapproval.getRefRecord();

  return gr.document_id.getRefRecord();
}

i tried doing z.addQuery ("document_id.number", "STARTSWITH", "BKNG") but it doesn't works. i don't know how to do.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't dot-walk the document_id field when using .addQuery() as it is not a reference filed. Instead, you can use the Approval for (sysapproval) reference field like so:

z.addQuery("sysapproval.number", "STARTSWITH", "BKNG");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!