Need to populate the approver based on amount selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 05:26 AM
HI Community,
I have a requirement, in catalog form we have these variables, based on the amount selected the approver need to be populated in the additional approver field. I have written a script but it is not working as expected it because the value in amount in eur will display as 400 000.00 and not as 400000.00 (we have used regex pattern in script to achieve this) because of this my existing script is not populating the approver details.
catalog client script:
How can we achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 05:58 AM - edited 03-28-2025 06:02 AM
Hello @suuriyas
Here are the changes:
1. You should remove spaces from amount_in_eur.
2. getXMLAnswer is recommended for async execution.
3. if (amt >= 500000) { --> just take this as else because you don't have any condition after this.
Updated Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Remove spaces from amount before sending
var amt = g_form.getValue("amount_in_eur").replace(/\s+/g, '');
var ru = g_form.getValue("reporting_unit");
var ajax = new GlideAjax('PaymentApproverFilter');
ajax.addParam('sysparm_name', 'vendorapproverFilter');
ajax.addParam('sysparm_reporting_unit', ru);
ajax.addParam('sysparm_amount', amt);
ajax.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('approver', response);
} else {
g_form.clearValue('approver'); // Clear if no approver found
}
});
}
Updated Script Include:
var PaymentApproverFilter = Class.create();
PaymentApproverFilter.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
customerRefund: function(rep_unit, amt_in_eur) {
var answerRefund = [];
var pay = new GlideRecord('x_kaoy_finops_payment_form_approvers');
var amtInt = parseFloat(amt_in_eur).toFixed(2);
pay.addQuery('reporting_unit', rep_unit);
if (amtInt < 100000) {
return ''; // No approval needed
}
if (amtInt < 500000) {
pay.addQuery('min_amount_in_approval_eur', '<=', amtInt);
pay.addQuery('max_amount_in_approval_eur', '>', amtInt);
} else {
pay.addQuery('min_amount_in_approval_eur', '<=', amtInt);
pay.addEncodedQuery('max_amount_in_approval_eur=NULL');
}
pay.addEncodedQuery('active=true^approver_for_payment_types=Customer Refund');
pay.query();
while (pay.next()) {
answerRefund.push(pay.approver.toString());
}
return answerRefund.toString();
},
getcustomerRefundApprovers: function() {
var ru = this.getParameter("sysparm_reporting_unit");
var am = this.getParameter("sysparm_amount");
return this.customerRefund(ru, am);
},
vendorapproverFilter: function() {
var ru = this.getParameter("sysparm_reporting_unit");
var am = this.getParameter("sysparm_amount");
var amt = parseFloat(am).toFixed(2);
var gr = new GlideRecord('x_kaoy_finops_payment_form_approvers');
var answer = [];
gr.addQuery('reporting_unit', ru);
if (amt < 100000) {
return ''; // No approval needed
}
if (amt < 500000) {
gr.addQuery('min_amount_in_approval_eur', '<=', amt);
gr.addQuery('max_amount_in_approval_eur', '>', amt);
} else {
gr.addQuery('min_amount_in_approval_eur', '<=', amt);
gr.addEncodedQuery('max_amount_in_approval_eur=NULL');
}
gr.addEncodedQuery('active=true^approver_for_payment_types=Vendor Payment');
gr.query();
while (gr.next()) {
answer.push(gr.approver.toString());
}
return answer.toString();
},
type: 'PaymentApproverFilter'
});
Hope that helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 06:02 AM
Hi,
Some pointers
- Can you update your so your script is in a code block for readability
- When you say not working, have you checked the response being returned? Are you getting a response from your Ajax call?
- What's the field type for additional approvers?
- In your lookup table, is the column a string or a currency field?