- 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:45 AM
Maybe you should try to parse the information to integers. Also make sure that both variable are mandatory, because the function parseInt will not work with an empty string.
For example:
function onSubmit() {
var amount = g_form.getValue('reimbursement_request_amount');
var approvedAmount = g_form.getValue('reimbursement_approved_amount');
amout = parseInt(amount);
approvedAmount = parseInt(approvedAmount);
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;
}
}
Let me know if this works.
Kind regards,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 12:12 PM
It seems a good solution. However, the value can be broken in cents.
Can we use a parseFloat as well? If so, how?
- 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 01:53 PM
Great! It worked for me with me, but with the parseFloat instead of parseInt.
Thank you very much 🙂