Can we have two different reference fields of the same table ?

naresh1019
Mega Expert

Probably the tile may not be complete informatiove ......

1) A custom table need a Mail-Id to be selected from sys_user table.

2) I checked the display value in the sys_user table all fields, and is having false   value for all the fields.

3) when i created a reference field name is getting populated.

provide a solution.

13 REPLIES 13

Hi Naresh,



Please try below client script


find_real_file.png


Rashmi,



I think I am not able to represent my Requirement Correctly . So I am writing it again.



1) Custom Table with only one Reference field ---> Refering Table is sys_user.


find_real_file.png



2) Question: If I click on the reference icon, and select any record what will the field contains.



3) As of now it is filling with name.


find_real_file.png


4) Problem/Solution Required--> I want the field to be filled with Mail Id , not with name . like shown below


find_real_file.png


5) But the Condition is i dont want to change the display value to true for email as it will impact the caller field in the incident table.


Hi Naresh,



You can create another field for getting the user record and then from that record you can get the email-id, same like I mentioned in my previous reply.



Thanks,


Rashmi


Harsh Vardhan
Giga Patron

why don't you create another field to populate user email address? if you want to change the selection of user name to E-Mail id it will impact globally. even in the existing reference field. it will make the changes.


if in future you will create another reference type user it will not give you the name .it will always show you user email id.



you can populate user email through dot walk.


if you are on form you can refer the link below.


Dot-Walking - ServiceNow Wiki



if you handling it over catalog form then write onChange() client script. by using call back function.




10.6 getReference

GlideRecord getReference(fieldName, callback)


Returns the GlideRecord for the record specified in a reference field. If the referenced record cannot be found, then it returns an initialized GlideRecord object where currentRow = -1 and rows.length = 0.
getReference() accepts a second parameter, a callback function.
Callback function support for ServiceCatalogForm.getReference is available.
Warning: This requires a call to the server so using this function will require additional time and may introduce latency to your page. Use with caution. See Avoid Server Lookups.
Parameters:
fieldName - specifies the reference field.
Returns:
GlideRecord - the GlideRecord object for the record in specified in the reference field. See GlideRecord for more information.
  • If a callback function is present, this routine runs asynchronously, and browser (and script) processing will continue normally until the server returns the reference value, at which time the callback function will be invoked.
  • If a callback function is not present, this routine runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response. It is strongly recommended that a callback function be used on any supported versions.


Example: without a callback (don't do this)
function onChange(control, oldValue, newValue, isLoading) 
{ var caller = g_form.getReference('caller_id');
if (caller.vip == 'true')
alert('Caller is a VIP!');
}
Example: with a callback (recommended)
function onChange(control, oldValue, newValue, isLoading) { 
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
}
function doAlert(caller)
{ //reference is passed into callback as first arguments
if (caller.vip == 'true')
alert('Caller is a VIP!');
}


Hope it will help you