Display Read Only Details from another table

phil34
Tera Expert

Hi All,

I have a use case where I need to present some details from a related record on another table in the current view.

I have created a new view of the location form (cmn_location) in that view I have multiple reference fields that point to different vendors in the core_company table. in the below screenshot when each vendor is selected "on-change" within the Location form, I want to display some key details from the vendor records as read only such as the Support Phone Number for example in the red circled area.

phil34_0-1699239490423.png

 

Below is a zoomed in area showing the reference field

phil34_1-1699239569007.png

Below is where I want to display the phone number

phil34_2-1699239716576.png

and this is the phone number field in the vendor form (core_company) that I want to display

phil34_3-1699239938225.png

I am not very good at scripting so if there is a lot of it then I might need a bit of hand holding to make this work but secretly hoping its simple :-).

I assume that if I can get it working on one item if data then I can also display other pieces of data from the same vendor and the end game would be to have all the vendors that each location uses attached to the location form and displayed to the end users so they can access the details they need to get support from the vendors.

Any help would be greatly appreciated.



 



1 REPLY 1

yaswanthi2
Giga Sage

Hi @phil34 

You can write onchange client script for populating the user phone number

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') { //newValue is your onchange field name

g_form.setValue('u_phone', '');

} else {
var ga = new GlideAjax('myScriptUtils'); // client callable script include
ga.addParam('sysparm_name', 'populateUserNumber'); // function name
ga.addParam('sysparm_user', g_form.getValue('caller_id')); //form which user you want to populate the details
ga.getXML(UserNumberInfo);
}
}

function UserNumberInfo(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer != '') {
g_form.setValue('u_phone', answer); // set in your phone number field
}
}

Script Include:

populateUserNumber: function() {
var callerPhone = '';
var caller = this.getParameter('sysparm_user');
var grCaller = new GlideRecord('sys_user'); //call as per your requirement table
grCaller.addQuery('sys_id', caller);
grCaller.query();
if (grCaller.next()) {
callerPhone = grCaller.mobile_phone;
}
return callerPhone;
},