Auto-populate fields in Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2011 05:43 AM
Hello,
We currently have a very basic "Create a New Incident" record producer in our Service Catalog which asks for the user name of the individual, the category of the incident, and a description. The submitter is able to enter their user name or the user name of another person they are submitting the incident on behalf of. I'm trying to add other fields that will populate with information about the user such as their phone number and department from the sys_user table, but I can't seem to get it to work.
I searched for hours to find out how to do this with no luck, and made countless attempts. It seems like something that should be straightforward. Would anyone be able to tell me how to populate these fields once the user name is entered in the record producer?
TIA
-Joe
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2011 06:00 AM
Hi Joe,
First off, why would you want to populate these fields, if they are available from the sys_user record already? I'm assuming the data sent to incident, will need to be read by the agent picking up the incident. If that is the case, you could think about using the popup view for that agent for the relevant information, or use referenced fields to show the information directly on the incident (Personalizing forms on the wiki). For referenced fields, select the Caller field, and press the green + button next to it. It will then show the referenced fields which are the fields you mentioned in the question. Select department for instance. If you add it to the right part of the slushbucket it will show a greyish field which contains the referenced value of the user that was set in the caller field.
Now if you need to add information for the end user to see their own data (again, this should be discouraged, unless the purpose of the fields is any other than to be informative), you could think about using the default values on the variables in the field to autopopulate data. For instance, if your department field would be a reference to the department table:
javascript:gs.getUser().getDepartmentID();
In case it would be a string field with the department name:
javascript:gs.getUser().getRecord().getDisplayValue('department');
The latter also allows you to get other data from the currently logged in user. Just use the '
' to get the GlideRecord of the current user. For the phone number variable you could then use '
gs.getUser().getRecord()
' in the default value field of the catalog variable, to autofill that field.
javascript:gs.getUser().getRecord().getValue('phone');
Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2011 03:13 PM
I wanted to have the information there so that an end user can see and confirm the information. I am in a medical environment, so incidents may be called in from locations other than that listed on their sys_user record.
Also, a lot of doctor's have their assistant report incidents on their behalf so using gs.getUser() wouldn't always be practical. The fields would need to populate based on the value entered in the user name field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2011 01:21 AM
There is also a popup window available next to any reference field, so that the end-user can view the information from the record in that field.
If it is really necessary to populate fields you could try writing a catalog client script to populate the fields:
var x = g_form.getReference('<field containing user info>');
g_form.setValue('<field to show user info>', x.'<field available on user record>');
If you would like to have some location based information (where are you getting the location from?):
var x = g_form.getReference('<field containing location info>');
g_form.setValue('<field to show information from the location>', x.'<field available on the user record>');
If you would like to grab the location of the user and use that information to display the name of that location on the form:
var x = g_form.getReference('<field containing user location info>');
var y = new GlideRecord('cmn_location'); // location database
y.get(x.location); //object stores the location as a name value pair, get method captures the record based on sys_id
g_form.setValue('<field the location name should be store',y.name); // setValue sets data on the field
If you run it onChange the user from the field will automatically populate the fields designated by the code. Also add in some if/try catches if you are not sure whether the value exists or not.
For more information on how these scripts work you can refer to: Client Scripts and Catalog Client Scripts.
If information is retrieved from locations other than a user record, but is still available in the database, you can probably adapt the above scripts to match the needs.
Be sure to question the reason to script on the client side, as running scripts will always diminish browser performance. If information can be retrieved with measures already available, using them can often proof to be beneficial to the speed and experience a user gets when using the system. If there is no other option, this should provide enough of a solution hopefully. If not, please let me know, and I'll see what I can do for you.
Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2011 02:35 PM
The first one did it. I thought I tried that exact script, but apparently I had something wrong.
Thanks for the help!