Is there a way to reference multiple fields in a table?

dbrennan
Kilo Contributor

Hey everyone,

I'm making a request item that asks for information such as name, email, employee ID, etc. to be filled in.   On our company SN instance, we have a table that contains all of this information for each person in our organization.   I am curious if there is a way for me to make multiple variables within my request item to reference all of these fields?     I have set the display value for all of these variables mentioned above to true so that I could somehow reference each one for a specific entry in my item but it only ever references one of the columns.

Anyone have any information on how to do this?   I would really appreciate the assistance!

Thank you

1 ACCEPTED SOLUTION

Hello Devlin,



I'm making some assumptions here, but hopefully will have some advice that helps.


My advice assumes that your form as a catalog variable named "requested_for" which is the name of the person for which the other fields will be filled in. I also assume that requested_for is a reference variable pointing to a table with user information ( like sys_user ).



In a catalog client script, try something like this:


find_real_file.png



The script would be something like this ( but you'll probably make adjustments for your field names and names on the referenced table.



var user = g_form.getReference('request_for');


g_form.setValue('email', user.email);


g_form.setValue('first_name', user.first_name);


g_form.setValue('last_name', user.last_name);



If you're not familiar with the g_form object, I recommend that you take a look at this page:



http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0



Another page of interest would be the one on client scripts:



Client Scripts - ServiceNow Wiki


View solution in original post

8 REPLIES 8

Hi Devlin,



Auto populate those fields with default values.



user: javascript:gs.getUserID();


email: javascript:gs.getUser().getRecord().getDisplayValue("email");


employeeId: javascript:gs.getUser().getRecord().getDisplayValue("employee_id");



if for user changes, write a onChange client script by using GlideAjax class by writing script include.



// Reference will populate one true display value field only. we can show multiple values in the dropdown list but it display one field only.


The callback isn't required, but it isn't all the complicated either. The advantage of the callback is that the browser won't "lock up" while the reference is processed by the server.   Here's a pertinent example from the document I linked to above:


find_real_file.png



Your code goes where the alert statement appears in the examples.


Thanks! I eventually found this same article and basically did something similar by creating an alert callback function which either does the autofill i want to do if the user exists else, returns a user does not exist statement.   The issue is that the documentation says you don't need a callback and can leave it blank but when I left it blank, I was getting an error message saying that I can't leave the callback entry blank in the getReference function.   I am using Istanbul if that makes a difference.


I'm Helsinki. So it looks like I'm can expect more fun than usual when I upgrade.