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

Ct111
Tera Sage

var nm = g_form.setDisplayValue('requested_for');

g_form.setValue('second_variable_name', nm);

 

I hope this helps, write this on onCHange cilent script on field requested_For.

 

Mark my ANSWER as CORRECT and hELPFUL if it helps

 

 

Hi,

It wont give me full name. It will give me first name and Last name.

 

I need middle name as well.

 

Regards,

Shoheb Shaikh

You would have to write a script include where you will be GLIDING the sys_user

table and then setting the value on second variable via client script . I am just

giving it in short but do check some reference example of it.


Script Inlcude.:

var fnm = '';

var nm = this.getParameter('sysparm_nm');

var gr = new GLideRecord('sys_user');

gr.addQuery('sys_id',nm);

gr.query();

if(gr.next())

{

fnm = gr.first_name + ' '+ gr.middle_name + ' ' + gr.last_name;

}

 

return fnm;

 

Client script 

 

var gjax = new GlideAjax('ScriptIncludeName');

gjax.addParam('sysparm_name','NameofFunctionInScriptInclude');

gjax.addParam('sysparm_nm',newValue);

............... . blah blah

 

and then finally while returning that fnm value set it in CLient script

 

g_form.setValue('second_var',fnm);

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