gs.getUserID() doesn't work in agent mobile app?

e_wilber
Tera Guru

In the agent mobile app I am trying to pull back all active Work Order tasks assigned to the logged in user, and retrieve their parent Work Orders. This does not work in the mobile app but it works just fine as a background script or business rule.

From the mobile app, how do I get the logged in user so I can build this query?

(function getQueryString(input) {
//Type appropriate comment here, and begin script below
var woList = [];
var wot = newGlideRecord('wm_task');
wot.addQuery('active', true);
wot.addQuery('assigned_to', gs.getUserID());
wot.query();

while (wot.next()) {
woList.push(wot.parent.toString());
}

gs.log('mobile app: ' + input );
var queryString = 'sys_idIN' + woList.join(',');
return queryString;
})(input);
4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

You should be able to use gs.getUserID() just fine.

Check formatting:

var wot = newGlideRecord('wm_task');

to

var wot = new GlideRecord('wm_task');

Can you give a bit more information as to how it's not working?

It's also recommended to use: gs.info() instead of gs.log()

You should also be able to simply use: 

var queryString = 'sys_idIN' + woList;

If the records have all been pushed correctly and it consists of a comma separated array of sys_ids (check the value in a log statement).

Here's GlideRecord documentation as well: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Sorry, not sure why my copy and paste wasn't 100% accurate but I do have the gliderecord line correctly set up with the space between new and gliderecord.

This is a scoped app though (for field service mobile), does that make a difference?

When I copy and paste the entire code into the background script, it returns a list of all the Work Orders that I have at least one task assigned to me from. In the mobile app, it gives me zero results in my list.

Hi,

gs.getUserID() should still work in scoped application.

gs.log() however, does not work, please use gs.info() as mentioned above.

You'd want to ensure that you can access data from that other table from a scoped application. Check table settings, etc.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Rameswar1
ServiceNow Employee
ServiceNow Employee

Hi, You may want to use a function similar to the accepted solution of this thread (in case you still have the issue):

https://community.servicenow.com/community?id=community_question&sys_id=7b40c7a1db98dbc01dcaf3231f96...