how to read model's field value dynamically

  • 1
  • Question
  • Updated 1 year ago
  • Answered
Explained:

Suppose I've a field name in a string variable and i need to read that field's value from JavaScript. How do I do that?
Photo of Priya

Priya

  • 478 Points 250 badge 2x thumb

Posted 1 year ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
var params = arguments[0],
	yourModel = skuid.$M('YOURMODELID'),
	row = yourModel.getFirstRow(),
	yourDesiredValue = row.YourFieldName__c,
	$ = skuid.$;

console.log(yourDesiredValue);
Photo of Priya

Priya

  • 478 Points 250 badge 2x thumb
Thanks for the response.
That doesn't solve my problem. I need to get the model's field value, where my field name is stored in the String variable. I don't want to hard code 'YourFieldName__c'.
I need to get the field's value by taking the field name dynamically from the string variable.
Photo of Priya

Priya

  • 478 Points 250 badge 2x thumb
I found the solution for this, thought this might be helpful in the community so posting it.
var YourModel = skuid.model.getModel('YOURMODELID');
var row = YourModel.getFirstRow();
var fieldName = 'XYZ__c';
var yourDesiredValue = contactUs_UIOnlyData.getFieldValue(row,fieldName,true);