- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 05:47 AM
Hi All,
I have a requirement to calculate the Liability Violation Hours where Liability Violation Hours = Violation hours * Multiplier.
I have written a onChange Client script for above cal.
Everything is working fine except i cannot make the Liability Violation Hours(decimal type field) field as empty when the violation hours as empty.
Please help to correct my code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var vh = g_form.getValue("violation_hour");
var mul = g_form.getValue("multi");
var lvh;
if((mul!='' && vh != 0)){
lvh= vh*mul;
g_form.setValue("liability_violation_hours", lvh);
}
else if((mul==''|| mul!='')&& vh===0){
var ll=vh*mul*0;
g_form.setValue("liability_violation_hours", ll);
}
else if((mul==''|| mul!='')&& vh===''){
g_form.setValue("liability_violation_hours", '');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 05:43 AM
Hi @ST9
You can try the replace method below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue("liability_violation_hours");
return;
}
var violationHours = g_form.getIntValue('violation_hour') * g_form.getIntValue('multi');
g_form.setValue("liability_violation_hours", violationHours.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 07:09 AM - edited 11-14-2023 07:12 AM
Hi @ST9
If the field violation hours or multiplier is newValue then in above script in line 2 remove newValue==''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 08:13 AM
Hi @ST9
"Everything is working fine except i cannot make the Liability Violation Hours(decimal type field) field as empty when the violation hours as empty."
It's because of this condition in your script.
if (isLoading || newValue === '') { return; }
Let's try the below adjustment.
#OnChange Client Script (Violation hours)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.setValue("liability_violation_hours", '');
return;
}
var ll = newValue * g_form.getValue("multi");
g_form.setValue("liability_violation_hours", ll);
}
You can do the same for the Multiplier variable.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 12:47 AM
@Tai Vu : Hi, I have tried your code and it worked. Could you help me with adding the commas to correct places,
For example - if Multiplier is 1 and Violation hours = 111,111,111 then Liability Violation Hours = 111,111,111
but for me it shous without comma .. 111111111
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 05:43 AM
Hi @ST9
You can try the replace method below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue("liability_violation_hours");
return;
}
var violationHours = g_form.getIntValue('violation_hour') * g_form.getIntValue('multi');
g_form.setValue("liability_violation_hours", violationHours.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
}
Cheers,
Tai Vu