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 11:56 AM - edited 2021-03-05 03:59 PM
Rod, see how below works for you.
Update line 2 with the correct field name and line 17 is the text for the warning message to the user.
<script type="text/javascript">
var fieldName = 'Text (Calculated)';
// Hijack Save Button
$('#master_btnApply1, #master_btnApplyIcon').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Apply');return false;})
// Clone Save And Close Button
$('#master_btnSave1').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Save')});
// Hide Right-Click Save and Save and Close Right-Click Menu Items
$('.rmLink:Contains("Save")').parent().parent().hide();
$('.rmLink:Contains("Save and Close")').parent().parent().hide();
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-11 12:44 PM
I do not think I did it correctly. The bold in line two is the actual field name.
I dont get any error when I save the record.
Thank you so much for the help.
<script type="text/javascript">
var Customer Contact Number = 'Text (Calculated)';
// Hijack Save Button
$('#master_btnApply1, #master_btnApplyIcon').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Apply');return false;})
// Clone Save And Close Button
$('#master_btnSave1').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Save')});
// Hide Right-Click Save and Save and Close Right-Click Menu Items
$('.rmLink:Contains("Save")').parent().parent().hide();
$('.rmLink:Contains("Save and Close")').parent().parent().hide();
function checkPhoneNumber(action){
var getFieldId = lookupFieldId(fieldName);
if(Number($CM.getFieldValue(getFieldId).length)<10){
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-02-11 12:53 PM
Close and my bad for not being clearer.
It should be:
var fieldName = 'Customer Contact Number';
Advisory Consultant
2021-02-11 01:19 PM
No this is all my fault. I don't know the coding part of Archer. Do I have the custom object in the correct spot? It still doesn't work.
I put it under the field I need to format.
2021-02-11 01:27 PM
No worries
The placement doesn't matter. You should get a warning prompt when trying to save a record that doesn't have a complete phone number entered. The custom object is looking to see if the phone number entered is the correct length of 10 numbers.
Advisory Consultant
2021-02-11 01:35 PM
Here is the latest version. Do I have the fiedName in the correct spot? Object isnt working. Thank you
<script type="text/javascript">
var fieldName = 'Customer Contact Number';
// Hijack Save Button
$('#master_btnApply1, #master_btnApplyIcon').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Apply');return false;})
// Clone Save And Close Button
$('#master_btnSave1').unbind('click').prop("onclick", null).click(function(){ checkPhoneNumber('Save')});
// Hide Right-Click Save and Save and Close Right-Click Menu Items
$('.rmLink:Contains("Save")').parent().parent().hide();
$('.rmLink:Contains("Save and Close")').parent().parent().hide();
function checkPhoneNumber(action){
var getFieldId = lookupFieldId(fieldName);
if(Number($CM.getFieldValue(getFieldId).length)<10){
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-02-11 01:55 PM
The variable looks fine.
Make sure the custom object display is configured for Edit Mode. Also, see if any errors are thrown by open the browser developer tools and look at the console when you edit the record and click on the Save button.
Advisory Consultant
2021-02-11 02:28 PM
Here is what I get in dev tools.
<script type="text/javascript">
//<![CDATA[
window.__TsmHiddenField = $get('scriptManager_TSM');//]]>
</script>
</form>
</body>
</html>
2021-02-11 02:43 PM
Hmm, that's not from the custom object.
Is it listed as an error?
Can you post a screenshot of the console?
Advisory Consultant