tanaz
tanaz

Reputation: 11

Get specific field from property

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?

Upvotes: 0

Views: 97

Answers (2)

Sahil Thummar
Sahil Thummar

Reputation: 2500

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

Upvotes: 0

feedy
feedy

Reputation: 1150

Parse your result to JSON like this:

const analysisCodeObj = JSON.parse(analysisCode);

Get rf_code like this:

const rfCodeObj = analysisCodeObj["rf_code"];

Upvotes: 0

Related Questions