cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

display attribute value

former_member715858
Participant
0 Kudos
516

Good Day,

I will be greatful if some can advise me how to extract the state_name from the followng json file

https://sampleserver5.arcgisonline.com/arcgis/rest/services/AGP/Census/MapServer/3/query?where=1%3D1...

---------------------------------------------------

{"displayFieldName":"STATE_NAME","fieldAliases":{"STATE_NAME":"STATE_NAME"},"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":4269,"latestWkid":4269},"fields":[{"name":"STATE_NAME","type":"esriFieldTypeString","alias":"STATE_NAME","length":25}],"features":[{"attributes":{"STATE_NAME":"Hawaii"},"geometry":{"rings":[[[-160.07380355019365,22.00417730433918],[-160.04970969904335,21.988164105489[-155.53772980578589,19.042210637011351],[-155.6661923231172,18.921786344664099]]]}},{"attributes":{"STATE_NAME":"Washington"},

****************************************

Im trying to use the following code to consume API but I am not getting the state name correctly to display to the user

{ "type": "carousel", "delay": "", "content": [ {{#eachJoin api_service_response.default.body.fields}} { "title": "{{attributes}}", "subtitle": " {{name}}", "imageUrl": "", "buttons": [ { "title": "Select_L1", "value": "{{STATE_NAME}}", "type": "postback" } ] } {{/eachJoin}} ] }

**************************************

View Entire Topic
Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

I started by getting the displayFieldName:

{{api_service_response.default.body.displayFieldName}}

For the fields array, just iterate (there is only 1 member of the array in the sample service):

{
  "type": "buttons",
  "delay": "",
  "content": {
    "title": "Here is what we have for you. Take your pick.",
    "buttons": [
    {{#eachJoin api_service_response.default.body.fields}}
      {
        "title": "{{name}}",
        "value": "{{name}}-VALUE",
        "type": "postback"
      }{{/eachJoin}}
    ]
  }
}

For carousel:

{
  "type": "carousel",
  "delay": "",
  "content": [
     {{#eachJoin api_service_response.default.body.fields}}
     {
      "title": "{{name}}",
      "subtitle": "$ {{name}}-SUB",
      "imageUrl": "",
      "buttons": [
        {
          "title": "Buy",
          "value": "Buy",
          "type": "postback"
        }
      ]
    }{{/eachJoin}}
  ]
}
former_member715858
Participant
0 Kudos

Dear Dan,

Thank you for your reply .
The features array contains a list of all states names, as you can see , I got the total number 51 .
There is {{ length api_service_response.default.body.features}} in USA, Please select the State name that you want to inquiry about from the list below Response : There is 51 in USA, Please select the State name that you want to inquiry about from the list below


Now , I want to display the state name to user to select so I can run a query to extract and display information about
the POP on this state . 

{
  "type": "carousel",
  "delay": "",
  "content": [
     {{#eachJoin api_service_response.default.body.featuers}}
     {
      "title": "{{attributes}}",
      "subtitle": "$ {{attributes}}-SUB",
      "imageUrl": "",
      "buttons": [
        {
          "title": "Buy",
          "value": "Buy",
          "type": "postback"
        }
      ]
    }{{/eachJoin}}
  ]
}





former_member715858
Participant
0 Kudos

Hi there,

I am not sure why I can not iterate on features , I do have for sure 51 records to show. but it's only showing the first records by providing the id number

{ "type": "buttons", "delay": "", "content": { "title": "Here is what we have for you. Take your pick.", "buttons": [ {{#eachJoin api_service_response.default.body.features.[0]}} { "title": "{{STATE_NAME}} + title", "type": "postback" }{{/eachJoin}} ] } }

Dan_Wroblewski
Developer Advocate
Developer Advocate

In the original example you were trying to get fields and now you are trying to get features. I'm not sure what you are trying to do and what is working, not working.

Let's start with the original example -- did it work? Were you trying to get fields? Did you make a mistake?

former_member715858
Participant
0 Kudos
Thank you Dan, 

I replace the fields array with the features array and then I extract the value assigned to the state name .


{
  "type": "carousel",
  "delay": "",
  "content": [
   
     {{#eachJoin  api_service_response.default.body.features}}
     
     {
      "title": "{{attributes.STATE_NAME}}",
      "subtitle": "STATE_Name",
      "imageUrl": "",
      "buttons": [
        {
          "title": "{{attributes.STATE_NAME}}",
          "value": "{{attributes.STATE_NAME}}",
          "type": "postback"
        }
      ]
    }
    {{/eachJoin }} 
  ]
}
 

former_member715858
Participant
0 Kudos

Thank you Dan, This help me trace my code and explore the returned results.

Many Thanks