How to Autofill the reference field in Mobile?

Rosfield
Tera Contributor

Hi

I created a script to autofill the contact field with the user

System Definition > Script Includes

var GetDefaultContactValue = Class.create();
GetDefaultContactValue.prototype = {
    initialize: function() {},

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

    type: 'GetDefaultContactValue'
};

 

 Executable scripts

new sn_csm_mobile.GetDefaultContactValue().getDefaultValue();

 

This will not be executed.
Please tell me what is wrong with this script

 

I referenced these articles

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1166399

https://www.servicenow.com/community/mobile-apps-platform-forum/mobile-app-builder-auto-fill-assigne...

5 REPLIES 5

Murthy Ch
Giga Sage

HI @Rosfield 

Can you please keep some logs and check whether script include is returning values are not?

Thanks,
Murthy

Kerry P
Tera Contributor

I'd like to add on to this to ask why we can't use the "User" variable type to fill in a field that is a reference to the user table? What does the "User" variable return if not a usable link to the logged in user?

Marta Vicente R
Tera Contributor

Did you find the way autofill a reference input?

hello
What I wrote was the correct answer
Check the body and apply it
This should work fine