Check In and Out form that shows the current status in the form

615
4
Jump to solution
02-23-2022 07:33 AM
CHedger1227
New Contributor III

Hello All,

I am creating a check In/ Out form that will use one form to do this. Is there a way I can have it show the current status of each item in the form when they open it? I have created a dashboard that shows this but the people want to see it in the form itself. 

Example - item 1 is currently checked out of the office so when you open up the form choose item 1 from the drop down it will prepopulate and tell you it is currently checked out, you can add in a new record to check it in and it will create a new record.  

I hope this makes sense. 

Any help is welcome. 

Thank you
0 Kudos
1 Solution

Accepted Solutions
ZacharySutherby
Esri Regular Contributor

Hello @CHedger1227

One option would be to use a custom JavaScript function that queries the feature service based on an item selected from a choice list. Say for example you have a choice list with all the items and a user selects item 1, the JavaScript function would then query the feature service looking up the status of item 1 and return the status. 

Please see this post for an example on using a custom JavaScript function for querying a feature service: https://community.esri.com/t5/arcgis-survey123-questions/survey123-pulldata-from-another-survey/m-p/...

 

Then based on the response you can set some logic in your form it the item is checked out to prevent the form from being submitted. 

Thank you,
Zach

View solution in original post

0 Kudos
4 Replies
ZacharySutherby
Esri Regular Contributor

Hello @CHedger1227

One option would be to use a custom JavaScript function that queries the feature service based on an item selected from a choice list. Say for example you have a choice list with all the items and a user selects item 1, the JavaScript function would then query the feature service looking up the status of item 1 and return the status. 

Please see this post for an example on using a custom JavaScript function for querying a feature service: https://community.esri.com/t5/arcgis-survey123-questions/survey123-pulldata-from-another-survey/m-p/...

 

Then based on the response you can set some logic in your form it the item is checked out to prevent the form from being submitted. 

Thank you,
Zach
0 Kudos
CHedger1227
New Contributor III

Zach,

Thank you for the response.

I am not very familiar with JavaScript. I was able to look and somewhat understand your code. BUT i am getting an error that reads:

@javascript error:SyntaxError: JSON.parse: Parse error in queryLayer.js:returnFeatures

I changed my ID field and the URL, the data requires a token so i believe i  added it but am not sure i added it in the correct spot. I put it in the layerURL right after the FeatureServer/1.

Do you have any idea what it could be?

 

Thank you
0 Kudos
CHedger1227
New Contributor III

@ZacharySutherby 

I was able to fix the Parse Error but i have a couple of issues still. 

1. I am having issues with the token. I am unsure of how to add in the token to the JavaScript.

2. I can only get it to work with the ObjectID is there a way I can get it to work with a field that is not the ObjectID? if so how would I do that? 

Here is my code:

/*
* JavaScript functions for Survey123
*/

function returnFeatures(ID) {

// Output value. Initially set to an empty string (XLSForm null)
let outValue = "";

let layerURL = "https://.../ArcGIS/rest/services/.../FeatureServer/1"

// Set up query parameters
let f = "f=json";
let where = "where=OBJECTID="+ID;
let outFields = "outFields=*";
let returnGeometry = "returnGeometry=false";
let returnCount = "returnCount=1";
let parameters = [f,where,outFields,returnGeometry,returnCount].join("&");

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

// Create the request object
let xhr = new XMLHttpRequest();
// Make the request. Note the 3rd parameter, which makes this a synchronous request
xhr.open("GET", url, false);
xhr.send();


// Process the result
if (xhr.readyState === xhr.DONE) {
if (xhr.status !== 200) {
// The http request did not succeed
return "bad request: " + url
} else {
// Parse the response into an object
let response = JSON.parse(xhr.responseText);
if (response.error) {
// There was a problem with the query
} else {
if (response.features[0]) {
outValue = JSON.stringify(response.features[0]);
} else {
// No features found
}
}
}
}
return outValue;
}

 

Thank you
0 Kudos
ZacharySutherby
Esri Regular Contributor

Hello @CHedger1227

You can extract the token using `pulldata("@property", 'token')` please see this documentation for more information. 

Essentially what the JavaScript function is doing is querying the feature service to return information. To work with a different field you will need to change the where clause to be "where=<some field>=<some value>. 

In the example you have above it's set to `"where=OBJECTID="+ID` so the query is looking up based on objectId. 

Please see this documentation for more information on querying a feature service. 

Please note we also have a JavaScript sample available in Survey123 Connect that can be used for reference and additional examples. 

Thank you,
Zach