- 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 02:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 02:14 AM
Same issue. returning empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 04:09 AM
can you please share your code?
- 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-09-2024 12:22 AM
Hello @Rosy14
have you tried to auto-populate your variable?
https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/service-catalog-man...