Get specific field from property

89 Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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);

1
On

Parse your result to JSON like this:

const analysisCodeObj = JSON.parse(analysisCode);

Get rf_code like this:

const rfCodeObj = analysisCodeObj["rf_code"];