- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 01:17 AM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 02:48 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 01:38 AM
Hi @Rosy14 ,
Here's how you can achieve this:
Create a Script Include that will query the customer_account
table:
var CustomerAccountUtils = Class.create();
CustomerAccountUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompanyName: function(customerAccountId) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', customerAccountId);
gr.query();
if (gr.next()) {
return gr.name.toString();
}
return '';
},
type: 'CustomerAccountUtils'
});
​
Modify the Client Script to use GlideAjax
:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CustomerAccountUtils');
ga.addParam('sysparm_name', 'getCompanyName');
ga.addParam('sysparm_customerAccountId', newValue);
ga.getXMLAnswer(function(response) {
var company = response;
g_form.addInfoMessage(company);
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);
});
}
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 01:50 AM
It is returning empty. Nothing is returning from script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 01:52 AM
have you checked client callable checkbox ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2024 01:54 AM
yes