cancel
Showing results for 
Search instead for 
Did you mean: 

TextField - Read failing in custom objects using getFieldValue() function.

SanjayAgarwal
Contributor III

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? 

1 ACCEPTED SOLUTION

Accepted Solutions

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 - Archer, an RSA Business

View solution in original post

12 REPLIES 12

DavidPetty
Archer Employee
Archer Employee

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 - Archer, an RSA Business

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'

Please see the code example above.  What you have isn't how the getFieldValue() function works.

 Advisory Consultant - Archer, an RSA Business

Also make sure the field is on the layout and not in a tab that's not the default tab.

 Advisory Consultant - Archer, an RSA Business

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.

Can you post your complete custom object code?

 Advisory Consultant - Archer, an RSA Business

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>

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 - Archer, an RSA Business

Thanks again David! Also thanks for sharing correct way to read the mode of record. This will make coding much easier.