0

I am new to JavaScript and Dynamics CRM. I have following code:

var analysisCode = Xrm.Page.getAttribute("rf_analysiscode").getValue()[0].entityValues;

As value for analysisCode, I get following output:

{
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
}

But I want to get just the rf_code. How do I retrieve that?

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
tanaz
  • 11
  • 4

2 Answers2

0

Parse your result to JSON like this:

const analysisCodeObj = JSON.parse(analysisCode);

Get rf_code like this:

const rfCodeObj = analysisCodeObj["rf_code"];
feedy
  • 1,071
  • 5
  • 17
  • You are welcome, please feel free to accept it as a solution if it helped and don't hesitate to ask me any other questions. – feedy Mar 02 '22 at 10:12
0

Try this:

analysisCode = {
    "rf_name":{"name":"rf_name","value":"ABC"},
    "rf_code":{"name":"rf_code","value":"ABC"},
    "createdon":{"name":"createdon","value":"24.1.2022 10.39"}
};
let rf_code = analysisCode.rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);

If you are getting your output in String, Firstly need to parse output and then you can get any value from that json.

Try this:

analysisCode = '{"rf_name":{"name":"rf_name","value":"ABC"},"rf_code":{"name":"rf_code","value":"ABC"},"createdon":{"name":"createdon","value":"24.1.2022 10.39"}}'
let rf_code = JSON.parse(analysisCode).rf_code;
console.log('rf_code : ', rf_code);
console.log('rf_code Value : ', rf_code.value);
Sahil Thummar
  • 1,926
  • 16
  • 16