JavaScript Increment Based off another field in Survey123

290
0
02-10-2023 07:13 AM
DelaneyMccarthy
New Contributor

Hello! 

I am new to coding, and I want to set up a function that will assign a "sitenumber" at an incremental value for each different sourceid. What I would like is for the function to first search for a "sourceid" (which is being populated by pulldata from an attached csv file), then find the maximum sitenumber for that selection of rows with that sourceid and add 1 to the next sitenumber. I believe I should be using the search() and increment functions, but unsure of exactly how. 

Example: I have sourceid 1 and 2. I want sitenumber for sourceid 1 to go 1,2,3, etc. and sitenumber for sourceid 2 to go 1,2,3, etc. When new data is put in through the form, sourceid is autopopulated. Lets say to sourceid 2 in this example. I want the function to find the maximum sitenumber for sourceid 2 and add 1 to that. 

Any guidance is greatly appreciated! Thank you! 

0 Kudos
0 Replies