Sys_id to string value.

charmon
Kilo Contributor

I'm new to service now administration so please bare with me. I'm building a form and I need a few fields to autofill the information and its returning the user name as the sys_id not the string value. any help would be greatly appreciated

 

function onChange(control, oldValue, newValue) {

    var name = g_form.getReference('application_name');

    g_form.setValue('appowner', name.u_appowner);

}

 

the appowner field is populating the correct users sys_id but I need it as the actual name. Thank you in advance.

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Hi Chad,



if appowner is a reference field to the sys_user field then it will work as expected, else you will have to extract the user name from this name.u_appowner in the same was as you extracted u_appowner from application_name, ie using getReference.



a better approach will be   that you pass application_name to a script include using glideajax and there you can directly extract the u_appowner and get the display value of u_appowner by using .getDisplayValue().


-Anurag

View solution in original post

8 REPLIES 8

What exactly do you want to achieve....this is an old post....and if going through it doesn't solve ur issue then....tell me what you are trying


-Anurag

Ken83
Mega Guru

Using the .getDisplayValue() should give you what you are looking for.



function onChange(control, oldValue, newValue) {


    var name = g_form.getReference('application_name');


    g_form.setValue('appowner', name.u_appowner.getDisplayValue());


}


charmon
Kilo Contributor

Thank you for all the quick responses. The community involvement is rather refreshing.



Kenneth, when I used that .getDisplayValue()) it wouldn't return the sys_ID of the user anymore.



Anurag you win the prize on this one...... the appowner field was set to a single line text I changed it to a refrence to the sys_users and it resolved the issue.....



just so I dont get to many eye rolls on this, I have no training in service-now admin at all. I walked in one day and was told Hey guess what you are in charge of now........ so everything is self taught. alot of looking at what the company already had setup and trying to duplicate it on new work...... unfortunately it appears that a lot wasn't setup in the most efficient manor to begin with.



Again thank you for all the help everybody its much appreciated and I'm sure you will all be hearing from me again!!


I just experienced the same issue and your posting resolved it.....thanks a bunch !!!