New Service Portal throwing errors for just my user?

bbarber9
Giga Expert

This might be one of the weirdest errors I have encountered so far. The new service portal is throwing nullPointerExceptions when I visit the portal as myself, but if I impersonate anyone else it loads just fine. It logs the scripts that are breaking in my console which I will put below. The only thing I can think of that might have messed it up was importing new users from LDAP earlier today. Maybe my user got corrupted or something?

Offending Scripts:

Script 1:

var t = data;

t.items = [];

t.count = 0;

var u = gs.getUser().getID();

// use record watchers to tell header when to update dropdown counts

t.record_watchers = [];

t.record_watchers.push({'table':'sysapproval_approver','filter':'approver=' + u + '^state=requested'});

var z = new GlideRecord('sysapproval_approver');

z.addQuery("approver", gs.getUserID());

z.addQuery("state", "requested");

z.orderByDesc('sys_updated_on');

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();

}

Script 2:

(function(){if (input && input.op) {

  var app = new GlideRecord("sysapproval_approver");

  if (app.get(input.target)) {

      app.state = input.op;

      app.update();

  }

}

var gr = new GlideRecord('sysapproval_approver');

gr.setLimit(50);

var qc1 = gr.addQuery("state", "requested");

if (input)

  qc1.addOrCondition("sys_id", "IN", input.ids);

gr.addQuery("approver", gs.getUserID());

gr.orderBy("sys_created_on");

gr.query();

var approvals = [];

var ids = [];

while (gr.next()) {

  var task = getRecordBeingApproved(gr);

  if (!task.isValidRecord())

  continue;

  ids.push(gr.getUniqueValue());

  var t = {};

  t.number = task.getDisplayValue();

  t.short_description = task.short_description.toString();

  if (task.isValidField("opened_by") && !task.opened_by.nil())

    t.opened_by = task.opened_by.getDisplayValue();

  // requestor >> opener

  if (task.isValidField("requested_by") && !task.requested_by.nil())

    t.opened_by = task.requested_by.getDisplayValue();

  t.start_date = task.start_date.toString();

  t.end_date = task.end_date.toString();

  t.table = task.getLabel();

  if (task.getValue("price") > 0)

    t.price = task.getDisplayValue("price");

  if (task.getValue("recurring_price") > 0)

    t.recurring_price = task.getDisplayValue("recurring_price");

  t.recurring_frequency = task.getDisplayValue("recurring_frequency");

  var items = [];

  var idx = 0;

  var itemsGR = new GlideRecord("sc_req_item");

  itemsGR.addQuery("request", task.sys_id);

  itemsGR.query();

  if (itemsGR.getRowCount() > 1)

      t.short_description = itemsGR.getRowCount() + " requested items";

  while (itemsGR.next()) {

      var item = {};

      item.short_description = itemsGR.short_description.toString();

      if (itemsGR.getValue("price") > 0)

          item.price = itemsGR.getDisplayValue("price");

      if (itemsGR.getValue("recurring_price") > 0) {

          item.recurring_price = itemsGR.getDisplayValue("recurring_price");

          item.recurring_frequency = itemsGR.getDisplayValue("recurring_frequency");

      }

      if (itemsGR.getRowCount() == 1) {

          item.variables = $sp.getRecordVariablesArray(itemsGR);

          t.short_description = itemsGR.short_description.toString();

      }

      items[idx] = item;

      idx++;

  }

  var j = {};

  j.sys_id = gr.getUniqueValue();

  j.table = gr.getRecordClassName();

  j.task = t;

  if (task)

      j.variables = $sp.getRecordVariablesArray(task);

  j.items = items;

  j.state = gr.getValue("state");

  j.stateLabel = gr.state.getDisplayValue();

  approvals.push(j);

}

data.ids = ids;

data.approvals = approvals;

function getRecordBeingApproved(gr) {

  if (!gr.sysapproval.nil())

      return gr.sysapproval.getRefRecord();

  return gr.document_id.getRefRecord();

}

})()

1 ACCEPTED SOLUTION

bbarber9
Giga Expert

Ok I figured this out. In case anyone was wondering, I had an approval for a record that didn't exist anymore in my approvals. This would cause the getRecordBeingApproved method in the index page of the service portal to freak out and generate that massive stack trace. Deleting the approval fixed the issue!


View solution in original post

11 REPLIES 11

Thank you so much for the update - really useful!

@bbarber9 Can you please explain the steps here, How do I find that specific record and delete it as I am facing exact the same Issue.