Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Could you correct my client script, it doesn't work in portal

abbassi
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
var userinfo = g_form.getReference ('user');
//g_form.setValue ('ldap', userinfo.user_name);
    // Fonction pour réinitialiser les champs
    function resetFields() {
        g_form.setValue('email', '');
        g_form.setValue('bu_or_external_supplier', '');
   
        g_form.setReadOnly('email', false);
        g_form.setReadOnly('bu_or_external_supplier', false);
      //  g_form.setReadOnly('ldap', false);
    }

    // Fonction pour définir les champs
    function setFields(email, company) {
        g_form.setValue('email', email);
        g_form.setValue('bu_or_external_supplier', company);
       // g_form.setValue('ldap', ldap);
        g_form.setReadOnly('email', true);
        g_form.setReadOnly('bu_or_external_supplier', true);
        //g_form.setReadOnly('ldap', true);
    }

    var userRecord = new GlideRecord("sys_user");
    if (!userRecord.get(newValue)) {
        resetFields();
        return;
    }

    var emailUser = userRecord.getValue('email');
    var companyID = userRecord.getValue('company');
    //var ldapUser = userRecord.getValue('ldap'); 

    if (!companyID) {
        resetFields();
        return;
    }

    var companyRecord = new GlideRecord('core_company');
    if (!companyRecord.get(companyID)) {
        resetFields();
        return;
    }

    var companyName = companyRecord.getValue('name');
    if (companyName === 'GROUPE') {
        setFields(emailUser, companyName);
    } else {
        resetFields();
    }
}



1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@abbassi There are two issues with your client scripts.

1.  g_form.getReference ('user');  getReference call without a callback function are not supported in Service Portal. For more information please refer to https://www.servicenow.com/community/developer-forum/g-form-getreference-is-not-working-in-service-p...

 

2. var userRecord = new GlideRecord("sys_user"); Synchronous GlideRecord queries in client script in Service portal are not supported. Please consider shifting your GlideRecord queries to a Script Include and call them via GlideAjax.

 

Hope this helps.

View solution in original post

6 REPLIES 6

I guess you don't see any of the suggested 'alert()' results. I suggest that you provide additional details on the client script definition - screen shot. so Community members can see the table and field name.

 

Sandeep makes good points, see:

 

service-portal client-script-reference.html

 

Sandeep Rajput
Tera Patron
Tera Patron

@abbassi There are two issues with your client scripts.

1.  g_form.getReference ('user');  getReference call without a callback function are not supported in Service Portal. For more information please refer to https://www.servicenow.com/community/developer-forum/g-form-getreference-is-not-working-in-service-p...

 

2. var userRecord = new GlideRecord("sys_user"); Synchronous GlideRecord queries in client script in Service portal are not supported. Please consider shifting your GlideRecord queries to a Script Include and call them via GlideAjax.

 

Hope this helps.