Mobile App Builder Auto Fill assigned_to with User Variable

DJ Wolfson
Kilo Sage

I'm current making a Function with an Action Item to make a new record which requires the user set a an `assigned_to` field that references the `sys_user` table. My hope is to set the Autofill variable to the current user, however I'm not having any luck getting this to work. I've tried both making a Variable of type User and passing it in, and following another post found here to script getting the user's `sys_id` to be autofilled into the `assigned_to` input. Neither of the attempts above seems to populate the field on the Mobile Agent. Does anyone have a proper way to utilize the Autofill variable to set a reference to the `sys_user` table to the current user?

1 ACCEPTED SOLUTION

Hey, sorry for the delay. After double checking our Mobile Agent app, it looks like we were never able to successfully auto-assign this field.

 

Based on the KB you sent, it looks like they're saying you need a function within a Script Include that returns the currently logged in user. Here's documentation for getting User information: https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideSystemAPI%23r_...

 

I'll be honest, the article isn't very telling, but I think they're trying to say the function needs to return an object like this:

function getUserObject() {
    var object = {
        'Value': gs.getUserID(),
        'Display Value': gs.getUserDisplayName()
    };

    return object;
}

The KB is pretty odd, so the keys I gave above may not be what they actually are... I'm just going based off the KB. 

View solution in original post

5 REPLIES 5

Sharath Kumar V
Tera Contributor

Hi, were you able to achieve this requirement?
I have seen a now support article but I'm still wondering how to achieve this.

Autofill the reference field with some default value in Agent mobile app. - Support and Troubleshoot...

Hey, sorry for the delay. After double checking our Mobile Agent app, it looks like we were never able to successfully auto-assign this field.

 

Based on the KB you sent, it looks like they're saying you need a function within a Script Include that returns the currently logged in user. Here's documentation for getting User information: https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideSystemAPI%23r_...

 

I'll be honest, the article isn't very telling, but I think they're trying to say the function needs to return an object like this:

function getUserObject() {
    var object = {
        'Value': gs.getUserID(),
        'Display Value': gs.getUserDisplayName()
    };

    return object;
}

The KB is pretty odd, so the keys I gave above may not be what they actually are... I'm just going based off the KB. 

Hi @DJ Wolfson / @Sharath Kumar V 

 

Please find the below solution script provided by ServiceNow 

 

getUserObj : function ()
{
var userId = gs.getUserID();
var userName = gs.getUserDisplayName();
return {
    "Value" : userId,
    "DisplayValue" : userName
        };
}

Please mark this solution as correct.

This solution really helped me when struggling with the issue. Created the script include as provided in the support article.

Only difference was a space in 'Display Value', this was not working 😞

When I copied your solution which doesn't have space 'DisplayValue', It worked fine. 🙂

ServiceNow support article shouldn't have missed this minute detail.

 

Thanks,

Sudhir G