Integrating S123 and FieldMaps with an URL link with "&" symbol

422
4
Jump to solution
02-29-2024 03:09 PM
KenBouchard
New Contributor III

Hi,

I'm prepopulating fields in a S123 survey from the pop-up in FieldMaps.

Everything works great until I get some company name that have a "&" symbol in their name. (eg. Jack & Jill Farms)

The value stops at the "&" sign.  On the example above, it become only Jack.

Any advice?

Ken

0 Kudos
2 Solutions

Accepted Solutions
TylerGraham2
Occasional Contributor
KenBouchard
New Contributor III

Got it to work! 😁

The URL encoder is the solution.

Thanks a LOT for your help! 

(Here is a little how-to for anyone coming to this thread in the future)

Create an attribute expression:

KenBouchard_1-1710163939952.png

Put the code in with the encoder:

KenBouchard_0-1710163917363.png

and finally hyperlink it to the attribute expression

KenBouchard_2-1710164038003.png

 

Ken

View solution in original post

0 Kudos
4 Replies
TylerGraham2
Occasional Contributor
KenBouchard
New Contributor III

I'm passing it through an hyperlink in a text in the pop-up.  Not sure if/how I can use UrlEncode.

KenBouchard_1-1709310542714.png

 

This is the link URL I've created for it:

https://survey123.arcgis.app?itemID=36ff9e8c13e042a58cfce4ad87f55d19&field:Field_ID={field_id}&field...

I've never used UrlEncode, not sure how to use it.  I tried putting the whole thing, shown on the help page, in the Link URL, didn't worked... (I don't think it can handle variable...)

Thanks for your help.

Ken

 

 

0 Kudos
TylerGraham2
Occasional Contributor

UrlEncode is supposed to take whatever you pass through it encode the non-ASCII characters.  Passing it through the encoder should fix your Jack & Jill issue since it should take the & and replace it with the encoded value of %26. You'll need to create an arcade expression in your pop up to use it.  I parsed out the relevant parts from a larger script of mine. You'll want to replace my unique variables with yours for passing attribute values between field maps and the survey. I like to set all of those variables near the start so they are all in one place and it is easier to track down problems.  

For example your field id should be something like:

var field_val = $feature.field_id;

Var establishes that you are creating a variable with the name field_val.  To call the attribute value from a field in the feature layer use $feature.<field_name>.  In this case we are saying the variable equals whatever attribute value is in the feature's field_id field.  

In the params variable you put all the parameters you need to attach to the suvey123 url. This includes passing field values, survey action, callbacks, etc.  So to pass your field_id value to the survey"s Field_ID field you need to add a line in there that is:

"field:Field_ID": field_val,

If you look at the url you put together manually this is the part that we are creating: field:Field_ID={field_id}. UrlEncode will try to turn the colons in the line not in quotations into an equal sign, so it is important to make sure the field:Field_ID is in quotes otherwise it will be spit out at field=Field_ID which won't work.  

For the next field value to pass create a new variable for the $feature at the top of the script, then start a new line in params and repeat the "field:<field_name>": <variable>, format.

var item_id = <your survey123 id goes here>;
var map_id = <web map id goes here>;
var proj_val = $feature.project;
var globalid = $feature.GlobalID;

var urlsource = 'arcgis-survey123://?';
var fmurl = 'https://fieldmaps.arcgis.app?';
var recmess = Text("Enter Notes");
//Link display text
var fmfullurl = fmurl+ 'referenceContext=open' + '&itemID=' + map_id;
// full url to reopen field maps

  var params = {
    //parameters for UrlEncode() to use
    itemID: item_id,
    //use form item id here to target specified survey
    action: 'collect',
    //action tells survey123 to start a new record
    "field:point_guid": globalid,
    //pass global id from feature to survey guid field 
    //cannot assign variable for guid field name here, so this      one must be entered here.
    "field:project": proj_val,
    //pass project from feature to survey project field
    update: 'true',
    callback: fmfullurl
    //callback reopens Field Maps after the survey is completed
  };
 
var fullURL = Concatenate([urlsource,UrlEncode(params)]);
//encode url parameters and concatenate with the survey123 url

var not_zelda = `<div style="text-align:center;">
    <a href="${fullURL}" target="_blank">${recmess}</a>
    </div>`
    //Set the html to creat a link and position it.     
    //The enclosing apostrophes used must be the ` located     
//under ~.

return {
  type: 'text',
  text: not_zelda,
  //this property supports html tags
  //This bit will take everything above and display a link   //in the pop up window
};

 

0 Kudos
KenBouchard
New Contributor III

Got it to work! 😁

The URL encoder is the solution.

Thanks a LOT for your help! 

(Here is a little how-to for anyone coming to this thread in the future)

Create an attribute expression:

KenBouchard_1-1710163939952.png

Put the code in with the encoder:

KenBouchard_0-1710163917363.png

and finally hyperlink it to the attribute expression

KenBouchard_2-1710164038003.png

 

Ken

0 Kudos