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.

catalog client script

Rosy14
Kilo Sage

Hi,

I have a field on form company. Here if the value contain something based on it another field will auto populate, below script not working.

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

    //Type appropriate comment here, and begin script below

    var gr = new GlideRecord('customer_account');
	gr.addQuery('sys_id',newValue);
	gr.query();
	g_form.addInfoMessage(gr); //not printing
    var company, x;
    while(gr.next()) {
        company = gr.name;
    }
    g_form.addInfoMessage(company); //not printing
    if (company.toString().indexOf("CASA") >= 0 || company.toString().indexOf("CASA") >= 0 || company.toString().indexOf("casa") >= 0 || company.toString().indexOf("LI & FUNG") >= 0)
        x = 2.5;
    else
        x = 0;
    g_form.setValue("u_commission_rate", x);

}
1 ACCEPTED SOLUTION

Rosy14
Kilo Sage

This works for me 

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

    if (g_form.getUniqueValue() == "f84d8aad1b07fd900f52a797b04bcb2e") {
        var company = g_form.getDisplayValue('account');
        var x;
        if (company.indexOf("CASA") >= 0 || company.indexOf("casa") >= 0 || company.indexOf("LI & FUNG") >= 0) {
            x = 2.5;
        } else
            x = 0;
        g_form.setValue("u_commission_rate", x);
    }

}

View solution in original post

9 REPLIES 9

Hi @Rosy14 ,

 

Try the below script in Script Include and check:

 

	getCompanyName: function() {
		var customerAccountId = this.getParameter('sysparm_customerAccountId');
		var ans = '';
        var gr = new GlideRecord('customer_account');
        gr.addQuery('sys_id', customerAccountId);
        gr.query();
        if (gr.next()) {
            ans = gr.name.toString();
        }
        return ans;
    },

Mark the response correct and helpful if the answer assisted your question.

Same issue. returning empty

can you please share your code?

 

Rosy14
Kilo Sage

This works for me 

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

    if (g_form.getUniqueValue() == "f84d8aad1b07fd900f52a797b04bcb2e") {
        var company = g_form.getDisplayValue('account');
        var x;
        if (company.indexOf("CASA") >= 0 || company.indexOf("casa") >= 0 || company.indexOf("LI & FUNG") >= 0) {
            x = 2.5;
        } else
            x = 0;
        g_form.setValue("u_commission_rate", x);
    }

}

Aleks5
Tera Contributor