Get a field value from a table and set this field value on Service Portal form field

john303
Kilo Explorer

Hi everyone,

I created a table, name is users_phone. This table have a phone_number field and this field filled by it users. I want to create a Request, from the Service Portal and request form have variable name is Own_Phone_Number. So I want to get phone_number field value from users_phone table and set this value request form variable Own_Phone_Number field when users creating Request. I tried catalog client script or business rule, but i didn't get any solution. Please help for   this issue.

1 ACCEPTED SOLUTION

Hello Huseyin,



The following Catalog Client Script should work for you. Create a OnChange script with Field set as the Name of the Field which refers to the user_phone table.




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




var gr = new GlideRecord('users_phone');


gr.addQuery('NameOfFieldInUsers_phoneTable', newValue);


gr.query();


if(gr.next()){


g_form.setValue('Own_Phone_Number',gr.mobile_phone);


}



   


}


View solution in original post

11 REPLIES 11

john303
Kilo Explorer

Not reference field. Users have external data or voice sim cards.


Hello Huseyin,



The following Catalog Client Script should work for you. Create a OnChange script with Field set as the Name of the Field which refers to the user_phone table.




function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




var gr = new GlideRecord('users_phone');


gr.addQuery('NameOfFieldInUsers_phoneTable', newValue);


gr.query();


if(gr.next()){


g_form.setValue('Own_Phone_Number',gr.mobile_phone);


}



   


}


Thank you Eash,


This script useful and i change some variable fields , working good.


john303
Kilo Explorer

Thank you Eash, this script simply get table field value and set to another field. But this field needs to be filled according to the name of the requested_for.


This is the complicated part. I could not figure out how to write this code. If requested_for X ,get the table value X's phone number. If I change the requested_for Y, get the table   value Y' s phone number. It must be a dynamic variable field.


The above solution by Eash will work. The onhange field should be the request for field



Please mark this response as correct or helpful if it assisted you with your question.