- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 07:18 AM
Hello abhi_r
I tried the script you helped me revise and the results are the same.
I entered in 130,000 and it throws up the box saying "It is not a valid number" and then clears it out completely.
So I needed the following:
Script on a field that would pop up a warning if the amount was under $1mil - Working
The same field to convert to for as follows: $1,000,000.00
And for it to be able to accept commas "," - Our data is being passed with commas - Example 130,000 so that error I get would be thrown every time.
Here's the actual script I used.
function onLoad() {
Event.observe($('ast_contract.u_coverageamt_string'), 'change', function() {
var varHtml=$('ast_contract.u_coverageamt_string');
if(varHtml.value!=''){
if(!(/(^\d*\.\d*$)|(^\d*$)/g.test(varHtml.value))&& !(/(^\$\d*\.\d*$)|(^\$\d*$)/g).test(varHtml.value)){
alert("It is not a valid number");
g_form.setValue('u_coverageamt_string','');
}
else{
var formatted_value='';
if(varHtml.value.indexOf('.')>-1){
if(varHtml.value.indexOf('$')>-1){
formatted_value=varHtml.value.split('.')[0].replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.value.split('.')[1];
g_form.setValue('u_coverageamt_string',formatted_value);
}
else{
formatted_value="$"+varHtml.value.split('.')[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.value.split('.')[1];
g_form.setValue('u_coverageamt_string',formatted_value);
}
}
else{
if(varHtml.value.indexOf('$')>-1){
formatted_value=varHtml.value.replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
g_form.setValue('u_coverageamt_string',formatted_value);
}
else{
formatted_value="$"+varHtml.value.replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
g_form.setValue('u_coverageamt_string',formatted_value);
}
}
if((parseFloat(g_form.getValue('u_coverageamt_string').split('.')[0].replace(/\D/g, ""))<1000000)){
alert("Insurance amount is less than $1 million. Please ensure all appropriate documentation/exemptions is uploaded and/or vendor has Umbrella insurance $1 million or more.");
}
}
}
});
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 09:29 AM
Here is the complete script.
function onLoad() {
Event.observe($('incident.u_custom_currency'), 'change', function() {
var varHtml=$('incident.u_custom_currency');
if(varHtml.value!=''){
if(!(/(^\d*\.\d*$)|(^\d*$)/g.test(varHtml.value.replace(/,/g,'')))&& !(/(^\$\d*\.\d*$)|(^\$\d*$)/g).test(varHtml.value.replace(/,/g,''))){
alert("It is not a valid number");
g_form.setValue('u_custom_currency','');
}
else{
var formatted_value='';
if(varHtml.value.indexOf('.')>-1){
if(varHtml.value.indexOf('$')>-1){
formatted_value=varHtml.value.split('.')[0].replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.value.split('.')[1];
g_form.setValue('u_custom_currency',formatted_value);
}
else{
formatted_value="$"+varHtml.value.split('.')[0].replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.value.split('.')[1];
g_form.setValue('u_custom_currency',formatted_value);
}
}
else{
if(varHtml.value.indexOf('$')>-1){
formatted_value=varHtml.value.replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
g_form.setValue('u_custom_currency',formatted_value);
}
else{
formatted_value="$"+varHtml.value.replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
g_form.setValue('u_custom_currency',formatted_value);
}
}
if((parseFloat(g_form.getValue('u_custom_currency').split('.')[0].replace(/\D/g, ""))<1000000)){
alert("Coverage is not enough");
}
}
}
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 09:50 AM
Glad I could help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2016 02:56 PM
Question for you, What you helped me with is working perfectly but it's a client script. We have a webservice creating the contracts for us and of course it's skipping the Client Script actions...
I assume I need an "after" business rule to convert to a number. Don't need the warning but when a user opens this record, I need it to not allow them to update with the number as shown below.
Could it be part of the same script you gave me or is it a whole new one?
Integrations are tough when you're learning!
thanks for your help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2016 06:06 PM
You will need a before business rule for this. Put this script inside the function declarations. Put your filed name in the highlighted portions.
var varHtml=current.<field name>;
if(!(/(^\d*\.\d*$)|(^\d*$)/g.test(varHtml.replace(/,/g,'')))&& !(/(^\$\d*\.\d*$)|(^\$\d*$)/g).test(varHtml.replace(/,/g,''))){
gs.addInfoMessage("It is not a valid number");
current.<field_name>='';
}
else{
var formatted_value='';
if(varHtml.indexOf('.')>-1){
if(varHtml.indexOf('$')>-1){
formatted_value=varHtml.split('.')[0].replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.split('.')[1];
current.<field_name>=formatted_value;
}
else{
formatted_value="$"+varHtml.split('.')[0].replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.'+varHtml.split('.')[1];
current.<field_name>=formatted_value;
}
}
else{
if(varHtml.indexOf('$')>-1){
formatted_value=varHtml.replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
current.<field_name>=formatted_value;
}
else{
formatted_value="$"+varHtml.replace(/,/g,'').replace(/(\d)(?=(\d{3})+$)/g, '$1,')+'.00';
current.<field_name>=formatted_value;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2016 08:11 PM
Awesome. I'll put up a new post since this is different all together again.
Get Outlook for iOS<https://aka.ms/o0ukef>