How to populate user in reference fields based on currency value given
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 11:55 AM - edited 08-24-2023 11:56 AM
Hi All,
I have a requirement , populate users based on the currency value given in the gross sale value field (currency type). For this requirement i have created on load client script , Script is working fine users are populating in there fields. Here my issue is based on those field approvals are triggering from workflow . Every time form loading user getting 2 seconds late and approvals are not getting its directly going to close complete state. by using on load script.
1) i have written onchange client script also : In currency field type value populating with comma based on comma values client script are not working . for that i have created one field string and written a business rule to copy that value using before insert :
current.u_gross_sales_values = current.u_proposed_gross_sales;
While creating onchnage script user are not populating . Please help me on this.
Onchange script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var SBU = g_form.getValue('u_sbus');
var values = '';
if ((newValue >= 100000 && newValue <= 999999.99) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else if (values == '') {
g_form.clearValue('u_dir_fp_a');
}
if ((newValue >= 1000000 && newValue <= 1999999.99) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f'); // Dixie Manion
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else if (values == '') {
g_form.clearValue('u_vp_of_finance');
}
if ((newValue >= 1000000 && newValue <= 1999999.99) &&
(SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' ||
SBU == 'product_management')) {
g_form.setValue('u_cdo_cco_cso', 'fdc5fbdbdbe14050230aed384b961916'); // Val Cavelloro
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else if (values == '') {
g_form.clearValue('u_cdo_cco_cso');
}
if ((newValue >= 2000000) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_president', 'f7973bdb1ba980107d28a8ecbc4bcb73'); // Bill Glusing
g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f'); // Dixie Manion
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else if (values == '') {
g_form.clearValue('u_president');
}
}
Onload script:
function onLoad() {
var SBU = g_form.getValue('u_sbus');
var newValue = g_form.getValue('u_gross_sales_values');
var st = g_form.getValue('state');
if ((newValue >= 100000 && newValue <= 999999.99) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else {
g_form.clearValue('u_dir_fp_a');
}
if ((newValue >= 1000000 && newValue <= 1999999.99) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f'); // Dixie Manion
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else {
g_form.clearValue('u_vp_of_finance');
}
if ((newValue >= 1000000 && newValue <= 1999999.99) &&
(SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' ||
SBU == 'product_management')) {
g_form.setValue('u_cdo_cco_cso', 'fdc5fbdbdbe14050230aed384b961916'); // Val Cavelloro
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else {
g_form.clearValue('u_cdo_cco_cso');
}
if ((newValue >= 2000000) &&
(SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' ||
SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' ||
SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' ||
SBU == 'product_management')) {
g_form.setValue('u_president', 'f7973bdb1ba980107d28a8ecbc4bcb73'); // Bill Glusing
g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f'); // Dixie Manion
g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd'); // Will Lasher
} else {
g_form.clearValue('u_president');
}
}
Please help me on this
Value coping after forming saving
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 02:26 PM
You mentioned that the OnLoad script is causing a delay and causing issues with workflow approvals.
If your script is taking too long to complete, it might impact the form loading process. Consider optimizing your script for performance.
Here are a few tips:
- Minimize unnecessary calculations or data fetching.
- Avoid loops and complex operations.
- Use asynchronous methods if you're fetching data from the server (e.g., GlideAjax) to prevent blocking.
you mentioned that the OnChange script is not working as expected when the currency field value has comma-based formatting. This could be due to how JavaScript handles numbers with commas.
you can use:-
newValue = newValue.replace(/,/g, ''); // Remove commas from the currency value
newValue = parseFloat(newValue); // Convert the string to a floating-point number
Also, it looks like you're using the " values" variable but not assigning any value to it. You might need to assign a meaningful value to this variable based on certain conditions in your script.
try to debug properly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 04:24 PM
Hello @suresh40,
I would say first of all move all these client scripts into UI Policy. I absolutely dont see any specific need for client script here. Everything can be easily accomplished by UI Policy, atleast what you are doing here with the scripts.
Now, If you can provide more details about what exactly you are trying to achieve that could be useful.
Kind Regards,
Swarnadeep Nandy