- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 01:44 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 01:59 AM
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
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 01:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 01:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 02:04 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â02-24-2021 01:59 AM
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
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader