cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
praneshJ
Helper III
Helper III

How to fetch option set values through FetchXML from entity.

Hello Experts,

I have a web page from where I am fetching the Entity data in JSON format using Ajax call.

 

I have 4-5 option sets in my entity and I want those option sets data as well in the JSON,
but everything is getting received in JSON format using AJAX as expected except Option set values.

 

For option sets values I am getting blank in JSON, please check the below image, highlighted in yellow are the options sets fields in my entity.

 

praneshJ_0-1604320223471.png

 

any quick help is really appreciable!!

 

Regards,

Pranesh

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Thanks for sharing that

Basically the fetch returns an object for any option set, you can use .Label to view the display label of your option set, or .Value to display the value of the option set itself:

 

"ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Label']}}",
"ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Value']}}",



If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

5 REPLIES 5
OliverRodrigues
Super User
Super User

hi, can you share the liquid code where you are building that list?

it's probably something wrong there when rendering/retrieving the optionset value




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Hello @OliverRodrigues ,

Thanks for your response,

please check the below liquid code I am using to generate the json data.

{% assign contactid = {{user.contactid}} %}
{% fetchxml feed %}
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='contact'>
<attribute name='contactid' />
   <attribute name='fullname' />
  

<order attribute='createdon' descending='true' />

<filter type='and'>
<condition attribute='contactid' operator='eq' value='{{contactid}}' />

</filter>
<link-entity name='cr8e7_stc_studentactivity' from='cr8e7_contactlookup' to='contactid' alias='StudentActvityandContactLink'>
  <attribute name='cr8e7_name' />
  <attribute name='cr8e7_grade' />
<attribute name='cr8e7_inschoolafterschool' />
<attribute name='cr8e7_activitydatetext' />
<attribute name='cr8e7_activitydate' />
<attribute name='cr8e7_emergentreaderactivity' />
<attribute name='cra04_remoteinperson' />
<attribute name='cr8e7_healthy_choice' />
  <attribute name='cr8e7_homeworkhelp' />
  <attribute name='cr8e7_math' />
  <attribute name='cr8e7_ravfl' />
  <attribute name='cr8e7_emergentreaderactivity' />
  <attribute name='createdon' />
  <attribute name='cr8e7_student_id' />
  <attribute name='cr8e7_student' />
  </link-entity>
</entity>
</fetch>
{% endfetchxml %}

{
"Default_Site_Details": [
{% for item in feed.results.entities %}
{
"Contact_ID": "{{ item.contactid }}",
"fullname": "{{ item.fullname }}",
"Student_name": "{{ item['StudentActvityandContactLink.cr8e7_name']}}",
"Grade": "{{ item['StudentActvityandContactLink.cr8e7_grade']}}",
"IS_AS": "{{ item['StudentActvityandContactLink.cr8e7_inschoolafterschool']}}",
"ActivityDateText": "{{ item['StudentActvityandContactLink.cr8e7_activitydatetext']}}",
"ActivityDate": "{{ item['StudentActvityandContactLink.cr8e7_activitydate']}}",
"ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity']}}",
"HealthyChoices": "{{ item['StudentActvityandContactLink.cr8e7_healthy_choice']}}",
"Math": "{{ item['StudentActvityandContactLink.cr8e7_math']}}",
"HomeworkHelp": "{{ item['StudentActvityandContactLink.cr8e7_homeworkhelp']}}",
"ravfl": "{{ item['StudentActvityandContactLink.cr8e7_ravfl']}}",
"Createdon": "{{ item['StudentActvityandContactLink.createdon']}}",
"Studentid": "{{ item['StudentActvityandContactLink.cr8e7_student_id']}}",
"Studentname": "{{ item['StudentActvityandContactLink.cr8e7_student']}}",
"Remote_inperson": "{{ item['StudentActvityandContactLink.cra04_remoteinperson']}}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]
}
----------------------
Note: ERA, Healthychoices, Math, Homework help etc are the options sets in my entity.

option set values_censored.jpg

Thanks for sharing that

Basically the fetch returns an object for any option set, you can use .Label to view the display label of your option set, or .Value to display the value of the option set itself:

 

"ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Label']}}",
"ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Value']}}",



If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Hello @OliverRodrigues ,

Thanks for your reply,

 

I tried using both .Lebel and .Value to view the label or value of option set, still its returning blanks in my response json,
please refer the below code

 

"Attendance": "{{ item['StudentActvityandContactLink.cr8e7_attendance.Label']}}",
        "Attendance_value": "{{ item['StudentActvityandContactLink.cr8e7_attendance.Value']}}", 
        
        "ERA": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Label']}}",
        "ERA_value": "{{ item['StudentActvityandContactLink.cr8e7_emergentreaderactivity.Value']}}", 

 

Please assist me on this, do I need to make any other changes?

 

Regards,

Pranesh 

OliverRodrigues
Super User
Super User

Hi, not sure you already solved the problem

the code should be fine, I noticed the cr8e7_emergentreaderactivity attribute is duplicated in your Fetch, not sure this is the problem though

and I can't see the attribute cr8e7_attendance in your Fetch, is that the correct name?




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Users online (1,871)