Pulldata using @javascript does not work on web form (Query the record with an attribute value)

1128
3
04-23-2021 09:35 PM
KerryKang
Occasional Contributor II

Hello Esri Survey123 team, @JamesTedrick , @Philip-Wilson  or @IsmaelChivite could you please help me,,,? 

 

I am creating a web form that will use the pulldata function to retrieve the attributes from another feature layer.

This is how I'd like to set up.

- Survey1 is used to create a project list and its detail information such as year, client, and team members.

- Survey2 is used to track hours per each project created in Survey1. I hope to use 'dynamic dropdown' for the project list but I am aware that it's not implemented yet. So the project list is coming from another CSV table hosted on AGOL.

- In Survey2, when user select a project name, the project name will be used to query the attributes in Survey1 feature layer, and pullout its relevant information. This will be done using pulldata javascript as it will access the feature layer directly which will be consistently updated by managers rather than using pulldata csv.

To do that, I created a JavaScript functions that query the record with 'where clause' only (not using x, y location), and I am supposed to get the attributes in json. It worked perfect when I tested in Connect and Survey123 app on mobile device, but in web form I can confirm that json result area is empty where I used pulldata @javascript, and therefore pulldata@json questions that I am using to get each attribute value are empty, too.

When I tested using with 'featureByLocation' from the sample form, it worked fine on the web form. So I am not sure why my function does not work on web form, assuming that something must be wrong with my code. I used something that may not recognized by web browser??

 

The images below show the reusult of my javascript request in the mobile app vs. web browser.

 

pulldata("@javascript", "getProjectDetail.js", "featureByAttribute", ${Project_Name}, ${Token}))

 

 Result in the mobile app

KerryKang_0-1619238838792.png

 

 

Result in the web form (empty)

KerryKang_1-1619238871586.png

 

 

This is what I did for scripting,.. sorry for poor coding. I hope to get some advice.

 

 

function featureByAttribute(projectName, token) {
// Output value. Initially set to an empty string (XLSForm null)
let outValue = "";

// Check to make sure both layerURL and location are provided
if (projectName == null || projectName == "") {
// The function can't go forward; exit with the empty value
return projectName;
}


// I used these variables to replace '=' and ''' in url
let newEqual = "%3D"
let sgQuote = "%27"

// Set up query parameters

let parameter1 = "where=Project_Name"
let parameter2 = [parameter1, newEqual,sgQuote,projectName,sgQuote].join('')
let parameter3 = "f=pjson&outFields=*&returnGeometry=false"
let parameters = [parameter2, parameter3].join("&");
let layerURL = 'https://services1.arcgis.com/..../FeatureServer/0'

if (token) {

parameters = parameters + `&token=${token}`;

}

let url = `${layerURL}/query?${parameters}`;

3 Replies
KerryKang
Occasional Contributor II

Hello, 

I'd like to provide more information what I have been today, but it still does not work.

I used a query page to get the accurate url pattern that I'd like to apply. I noticed that there was '+' for space, so I applied that in the url scheme in the Javascript file.

After I fixed, it will look like this (Project_Name = 'Sample Project-Phase1'). To confirm, I coped and pasted the url in the browser, and I could see the json return, just like shown in my mobile app and Connect.  However, it still shows nothing in the webform.

https://services1.arcgis.com/../FeatureServer/0/query?where=Project_Name+%3D+%27Sample+Project-Phase...

Should I pass x, y to get the json return in web form like the featureByLocation code sample in the Connect? I am still not clear what makes different in my javascript pulldata.

 

When I checked the development tool, it shows the error below. Does it indicate the error that I have,,?

"DevTools failed to load SourceMap: Could not load content for chrome-extension://.../sourceMap/chrome/content.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME"

KerryKang_0-1619500333295.png

 

0 Kudos
HeatherBell
New Contributor III

Hi @KerryKang, did you ever figure this out? I'm trying to do something similar.

Thankyou, 

Heather. 

GIS Analyst @ The Rivers Trust
0 Kudos
HeatherBell
New Contributor III
0 Kudos