The CreatorCon Call for Content is officially open! Get started here.

Client script to return request for manager name if application supervisor is blank

nkumari
Tera Contributor

In client script (on change, variable : Application) if senmanager value is blank it should return 'Requested For' Manager name.

 

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


//Type appropriate comment here, and begin script below
var ga = new GlideAjax('applicationIDPopulation');
ga.addParam("sysparm_name", "getApplicationDetails");
ga.addParam("sysparm_id", g_form.getValue('application_id'));
ga.getXML(getResponse);

function getResponse(response) {

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

var result = JSON.parse(answer);

g_form.addInfoMessage(g_form.getValue('application_id'));

g_form.setValue('populate_application_id', result.num);
g_form.addInfoMessage(result.senmanger);

if (result.senmanger != '') {

g_form.setValue('u_level_approval', result.senmanger);
else if (result.senmanger == '') {

var id = g_form.getValue('request_for');

var user = new GlideRecord('sys_user');
user.addQuery('sys_id',id);
user.query();
if (user.next()) {
g_form.setValue('u_level_approval', user.manager);
}
}


}

}

 

1 ACCEPTED SOLUTION

Shraddha Kadam
Mega Sage

Hello @nkumari,

 

Please update your client script with below and test your functionality :

Onchange field : Application Supervisor

Note : The default script contains a line that checks for newValue == ''" . You can remove that from if statement in the script and it will run below code.

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

    var appSupervisor = g_form.getValue('application_supervisor');
    alert(appSupervisor);
    var reqName = g_form.getValue('requested_for');

    var user = g_form.getReference('requested_for', doAlert);

    function doAlert(user) {
        alert('inside alert');
        if (appSupervisor == '') {
            alert("inside if");
            g_form.setValue('requested_for_manager', user.manager);
        }
    }
}

 

Please mark Correct and click the Thumb up if my answer helps you solved your issue. Thanks!

Appreciate your help !

 

Thank you.

If my response was helpful, please mark it as correct and helpful.
Thank you.

View solution in original post

5 REPLIES 5

Correct it helped me