Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda