Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2021-02-11 09:38 AM
Hello,
Does anyone have an existing custom object code for force a ph# format?
We need the users to enter phone number like this???-???-????. We wont let them save the record unless they use that format.
If you have code for this we would appreciate it.
Thank you
2021-02-11 04:00 PM
Here is console. Also you can see the ph# is not formatted properly.
2021-02-12 08:20 AM - edited 2021-03-05 04:00 PM
Ah, I see the issue. The initial custom object was for 6.8+ and the id of the Save and Save and Close buttons are different. I've updated the custom object below for the version you're on.
<script type="text/javascript">
var fieldName = 'Customer Contact Number';
// Hijack Save Button
$('#master_btnApply').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Apply');return false;})
// Clone Save And Close Button
$('#master_btnSave').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Save')});
function checkPhoneNumber(action){
var getFieldId = lookupFieldId(fieldName);
if(Number($CM.getFieldValue(getFieldId).length)<10 && Number($CM.getFieldValue(getFieldId).length)> 1){
WarningAlert('The phone number entered (' + fieldName + ') is not in the proper format of (###-###-####)',"Phone Number Error");
} else {
ShowAnimationAndPostback('master$btn' + action);
}
}
function lookupFieldId(fldName){
var goFindId = null;
var r = /^a$/;
try{
$('.FieldLabel').each(function(){
if(($(this).text().indexOf(fldName + ':') != -1) && ($(this).text().indexOf(fldName + ':') == 0)){
goFindId = $(this).find("span")[0].id;
return false;
}
});
} catch (err) {console.log(err)}
try {if (!goFindId) goFindId = $('.SectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
try {if (!goFindId) goFindId = $('.SubSectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
return goFindId ? $LM._layoutItems[goFindId.replace( /^\D+/g, '')].fieldId : 0;
}
$.expr[':'].findField = function(a, i, m) {
return $(a).text().replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_').match("^" + m[3].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_') + "$");
};
</script>
Advisory Consultant
2021-02-12 09:31 AM
Sorry we are in the dinosaurs here at Aetna. Thank you for your patience and getting this to work for us.
Thank you.
2021-03-05 12:46 PM
Hey David,
I don't think this works exactly the way I envisioned. I need it to only force phone number format when we are editing that field.
Now we cant edit any field if the phone number format isn't correct.
Can you recommend anything to add to the code to only force formatting when someone is editing the field.
2021-03-05 04:02 PM
Rod, try replaceing this line
if(Number($CM.getFieldValue(getFieldId).length)<10){
with
if(Number($CM.getFieldValue(getFieldId).length)<10 && Number($CM.getFieldValue(getFieldId).length)> 1){
Advisory Consultant
2021-03-05 05:10 PM
Thanks but that didn't work. The record did not have a phone number. I tried to edit another field but the record wont save.
The save and save and close buttons are there but they wont click. Here is the latest code after I made your change.
Please remember I am on an old version of Archer.
<script type="text/javascript">
var fieldName = 'Customer Contact Number';
// Hijack Save Button
$('#master_btnApply').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Apply');return false;})
// Clone Save And Close Button
$('#master_btnSave').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Save')});
function checkPhoneNumber(action){
var getFieldId = lookupFieldId(fieldName);
if(Number($CM.getFieldValue(getFieldId).length)<10 && Number($CM.getFieldValue(getFieldId).length)> 1){
WarningAlert('The phone number entered (' + fieldName + ') is not in the proper format of (###-###-####)',"Phone Number Error");
} else {
ShowAnimationAndPostback('master$btn' + action);
}
}
function lookupFieldId(fldName){
var goFindId = null;
var r = /^a$/;
try{
$('.FieldLabel').each(function(){
if(($(this).text().indexOf(fldName + ':') != -1) && ($(this).text().indexOf(fldName + ':') == 0)){
goFindId = $(this).find("span")[0].id;
return false;
}
});
} catch (err) {console.log(err)}
try {if (!goFindId) goFindId = $('.SectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
try {if (!goFindId) goFindId = $('.SubSectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
return goFindId ? $LM._layoutItems[goFindId.replace( /^\D+/g, '')].fieldId : 0;
}
$.expr[':'].findField = function(a, i, m) {
return $(a).text().replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_').match("^" + m[3].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_') + "$");
};
</script>
2021-03-08 10:05 AM
I think you are close, Please look at my code above.
The save and save close buttons are there, but you cant click them.
Thank you
2021-03-08 10:26 AM
Rod, any errors in the browsers console when you edit the record?
Advisory Consultant
2021-03-08 10:30 AM
Sorry should have included that.
SCRIPT5007: Unable to get property 'length' of undefined or null reference
2021-03-08 07:42 PM
Check that the expression $CM.getFieldValue(getFieldId) returns NULL in the IF condition.