- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 01:05 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 02:49 PM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 01:18 PM
Hi Devlin,
Create a variable Requester to refer user table. For other details use single line text fields and assign default value to these fields.
For example, the email could be retrived using below default value.
javascript:current.variables.requester.email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 02:14 PM
Hey Gurpreet,
I'm not sure how this would work. I'm assuming that current.variables.requestor.email would get the email of the current user? If that is the case, this solution would not work for me. The reason being that for the item I am creating, people can request this item for others. For example in most cases, it will be a team's manager requesting this item for one of their staff.
So basically, I have this request item with each one of these fields above, Email, First Name, and Last Name (others as well that haven't been implemented yet). What I want is for Email entry above to refer to the email column in a separate extensible company user table. First Name will reference the same table, only it will reference the First Name column and Last Name will reference the Last Name column in the same company user table.
I have been searching around and it seems like this is not as simple as I thought it would be to do but I can't seem to find any definite solutions.
Is there no way to simply reference different columns of the same table?
Thank you,
Devlin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2017 02:49 PM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 11:46 AM
Hey Steve,
This is great advice and sounds like it does exactly what I want! The only issue I'm having now, is that for the getReference() function I need to have a callback function? Is there a way to get around that? I don't really have a need for it, I just want to get the info for the user being referenced so I can auto fill the other boxes.
Any ideas?
Thanks,
Devlin