Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2020-07-10 12:11 PM
Hi,
We are trying to read the value of text field ( In field options it is text field and not text area) using custom objects like $CM.getFieldValue() by passing correct arguments. But it fails with error that textField.get_value() is not defined function.
As a wordaround I am using $("#textFieldID").html() to get the value but is there more generic way to read it in javascript?
2020-07-10 03:21 PM
Yes, that function only works in edit mode. You'll have to use $("#textFieldID") for view mode.
You can use the following to detect which mode the record is in (inside of Sys.Applicaton.add_load):
ArcherTech.UI.GenericContent.GetInstance().get_mode(); // 1 = Edit, 2= View
Advisory Consultant
2020-07-10 12:52 PM
Sanjay, calling the $CM.getFieldValue([field id]) needs to be called within the Sys.Application.add_load(function() { }); function like so:
Sys.Application.add_load(function() {
var txtFieldValue = $CM.getFieldValue(1234);
});
Advisory Consultant
2020-07-10 01:17 PM
Hi David,
Yes currently it is part of add_load method but still getting the error at in debugger windows at below code snippet -
, _getTextFieldValue: function (field, other, newValue) {
if (newValue !== undefined) {
return newValue;
}
var val = null, textField = null;
if (field.displayControl == 1) {
textField = this.getFieldControl(field);
if (textField) {
val = textField.get_value();
if (val == '') {
val = null;
}
}
}
The Bold portion above fails with error::
Object doesn't support property or method 'get_value'
2020-07-10 01:20 PM
Please see the code example above. What you have isn't how the getFieldValue() function works.
Advisory Consultant
2020-07-10 01:48 PM
Also make sure the field is on the layout and not in a tab that's not the default tab.
Advisory Consultant
2020-07-10 02:41 PM
I tried with one more field which is on default layout and kept minimal code as per example above but still getting same error. Any thoughts please.
2020-07-10 02:45 PM
Can you post your complete custom object code?
Advisory Consultant
2020-07-10 03:03 PM
Update: Below code works well in Edit mode but not in view mode. Do we have different function to read value in read mode?
<script type="text/javascript">
Sys.Application.add_load(function(){
var txtFieldValue = $CM.getFieldValue(122625);
});
</script>
2020-07-10 03:21 PM
Yes, that function only works in edit mode. You'll have to use $("#textFieldID") for view mode.
You can use the following to detect which mode the record is in (inside of Sys.Applicaton.add_load):
ArcherTech.UI.GenericContent.GetInstance().get_mode(); // 1 = Edit, 2= View
Advisory Consultant
2020-07-10 03:53 PM
Thanks again David! Also thanks for sharing correct way to read the mode of record. This will make coding much easier.