Concatenating JSON Strings in a pulldata() Request

309
2
12-07-2021 06:42 AM
Dylan_Wingler
New Contributor II

I'm trying to concatenate several attributes out of a JSON string in a pulldata() request. I've written a script to pull in data as a JSON string from another feature layer based on a geopoint. What I need is to combine multiple attributes from that JSON string to create the full mailing address.

Below is my current survey. In the Mailing Address calculation is all of the fields needed for the full mailing address.

SurveyEXCEL.png

 

Below is an example of the current output.

SurveyADD.png

The desire outcome for mailing address is:

PO Box 1129

New Bern, NC 28560

I've tried using pulldata("@json",${myjson}, concat("attributes.TMADDR", "attributes.CITYNM", "attributes.TAXSTE", "attributes.ZIP"))

as well as pulldata("@json",${myjson}, concat("attributes.TMADDR" + "attributes.CITYNM" + "attributes.TAXSTE" + "attributes.ZIP"))

 

Does anyone have any ideas?

0 Kudos
2 Replies
DougBrowning
MVP Notable Contributor

I would think you need to pull in each field into the form then concat the 123 fields.  You can make them hidden and set bind type to null so they are not shown on the form or in the service.

The pulldata call is not going to expect a function in the call itsefl, it is just text at that point.

Hope that helps

KimberlyMcCallum
New Contributor III

Do you mean that you are struggling to get all of the required address information into a correctly formatted address (as shown) to display to the user in a note field or something? It looks like from your screenshot, that some of your info may be incorrect (e.g., "attributes.PANAME" should be the owner according to your survey but it is returning the value "NEW BERN-CITY OF". Is that correct?). I'm probably missing something! 

In the past, I've done similar stuff by just writing another JavaScript function to handle and format that the output. Maybe something like the snippet below and then pass your attributes in another pulldata JS call? 

 
 

 

function formatAddress(address, city, state, zip){
  return `${address}<br>${city}, ${state} ${zip}`;
}