Catalog client script

shaikkhasim
Tera Contributor

Hi Team

i  created a catalog item (Device req) & created Requested for filed as (username).

hear my requirement is, once i selected the username . email id will fill automatically in Email field.(email back end value is "email")

pls guide me how to achieve these through catalog client script 

 

Thanks in advance 🧡🧡

Regards

khasim. 

 

khasim
1 ACCEPTED SOLUTION

Use this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ref = g_form.getReference('user_name', req_for);
    }
function req_for(ref) {
       
        g_form.setValue('email', ref.email);
    }
}
-Anurag

View solution in original post

8 REPLIES 8

Mounika30
Kilo Sage

Hi,

variable 1:--- Requested for

write in the default value ---- javascript:gs.getUserID();

variable 2:---email of Requested for

autopopulate --select the table dependent

select field to dotwalk

 

 

In script include

 

var forIctuser = Class.create();
forIctuser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserData: function() {

var usr = this.getParameter('sysparm_usr');

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', usr);

gr.query();

if (gr.next()) {

return gr.email.toString();

},

type: 'forIctuser'
});

 

Client:

 

function onLoad() {
//Type appropriate comment here, and begin script below

var abc = g_form.getValue('requested_by');

//alert('abcvalue:' +abc);

var ga = new GlideAjax('forIctuser');

ga.addParam('sysparm_name', 'getUserData');

ga.addParam('sysparm_usr', abc);

ga.getXML(processResponse);

}

function processResponse(response) {

var answer = response.responseXML.documentElement.getAttribute('answer');

alert(answer);

if (answer != '') {

// use backend names of catalog item variables

g_form.setValue('requested_for_email_address',email);

}

}

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can use this in an onchange catalog client script, that runs on change of the user record

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ref = g_form.getReference('<user variable>', req_for);
    }
function req_for(ref) {
       
        g_form.setValue('<email field to populate>', ref.email);
    }
}
-Anurag