Set First Name, Middle Name and Last Name in Catalog item

Shoheb Shaikh
Kilo Contributor

Hello Experts,

We have designed a Catalog item and it has 2 variables. Requested For (this fields get auto populated based on logged user). Requestor Full Name (This is a Single line text field).

I want to display requested for Full Name i.e. First Name, Middle Name and Last Name in the String field. If anyone changes the Value of requested for then automatically Requestor Full Name should be updated with the new Value.

How can I achieve this?

Regards,

Shoheb 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Shoheb Shaikh 

you can use this

getReference() with callback method using onChange client script on Requested For variable

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

var ref = g_form.getReference('requested_for', callBackMethod);

}

function callBackMethod(ref){

var firstName = ref.first_name;

var lastName = ref.last_name;

var middleName = ref.middle_name;

var finalValue = firstName  + ',' + middleName + ',' + lastName;

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Hi Ankur,

So this script works fine. However, instead of "," we want to add space between each name.

Also, how can I set by default value with firstname, middlename and lastname of the logged in user in the variable?

Regards,

shoheb

Hi,

So you can add space in above script

Now for the default value for logged in user

then you can use this in the default value of the variable

javascript: var value = ''; var user = new GlideRecord('sys_user'); user.get(gs.getUserID()); value = gr.first_name + ' ' + gr.middle_name + ' ' + gr.last_name; value;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

No luck.

find_real_file.png

Regards,

Shoheb

Hi,

small update

the GlideRecord object should be gr

javascript: var value = ''; var gr = new GlideRecord('sys_user'); gr.get(gs.getUserID()); value = gr.first_name + ' ' + gr.middle_name + ' ' + gr.last_name; value;

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur. Appreciated it. I have marked the above option as correct answer.