- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 11:19 AM - edited 08-12-2024 11:42 AM
Hello everyone.
I am involved in a task of calculating the difference between fields in a SCTASK as follows: the value of the reimbursement for financial loss ('reimbursement_request_amount') CANNOT BE GREATER than the value of the approved reimbursement amount ('reimbursement_approved_amount').
If the value of the second field is greater than the first, the form must not allow Update/Save. I've created an onSubmit catalog client script for this, but it's only working after one or two attempts and then block the submission of the form and generates the error message - no matter how lower is the value on 'reimbursement_approved_amount' field.
Could anyone help me with this?
Please find attached the catalog client script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var amount = g_form.getValue('reimbursement_request_amount');
var approvedAmount = g_form.getValue('reimbursement_approved_amount');
if (approvedAmount > amount) {
g_form.addErrorMessage('O valor aprovado de reembolso não pode ser maior que o valor do ressarcimento. Por favor, tente novamente');
return false;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 12:16 PM - edited 08-12-2024 12:25 PM
Yes, parseFloat is also a builtin function in Javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat
Just replace parseInt with parseFloat. I can be that there are difficulties with the format of the strings. Make sure you are using a '.' as separator.
For example:
function onSubmit() {
var amount = g_form.getValue('reimbursement_request_amount');
var approvedAmount = g_form.getValue('reimbursement_approved_amount');
// If necessary, first remove al " . " , then replace all " , " with " . "
amout = parseInt(amount.replace(/\./g, "").replace(/,/g, "."));
approvedAmount = parseInt(approvedAmount.replace(/\./g, "").replace(/,/g, "."));
if (approvedAmount > amount) {
g_form.addErrorMessage('O valor aprovado de reembolso não pode ser maior que o valor do ressarcimento. Por favor, tente novamente');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 11:49 AM
Trying clearing messages at the beginning of the script.
g_form.clearMessages();
Also consider an alternate approach with a script UI Policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 01:01 PM
You have to use parseFloat. Also shouldn't you be checking to if the amount is greater then the approvedAmount?
function onSubmit() {
//Type appropriate comment here, and begin script below
var amount = g_form.getValue('reimbursement_request_amount');
var approvedAmount = g_form.getValue('reimbursement_approved_amount');
if (parseFloat(amount) > parseFloat(approvedAmount)) {
g_form.addErrorMessage('O valor aprovado de reembolso não pode ser maior que o valor do ressarcimento. Por favor, tente novamente');
return false;
}
}