Select to view content in your preferred language

Incrementing Site_id

932
10
Jump to solution
05-31-2026 03:17 PM
DanHaynes123456
Occasional Contributor

Hi,

Creating a survey123 for to replace a legacy .mdb system.

I need to be able to create a site_id that consists of the project_code, users initials and an incrementing 4 digit integer so for example STAT + DJH + 0001 next site would be STATDJH0002. I need to be able to do this on and offline as crews are often working in remote locations.

I also need to create sample_id for sites where if multiple samples are collected the sample_id increments by 0.1 so for the above example first sample would be STATDJH0001.1 then STATDJH0001.2 etc.

As the site_id is tied to the users initials I am not worried about duplicate records, I am thinking if I create a hosted feature layer in our enterprise portal and populate it with all the possible combinations of site_id for each user (and have our SQL server update it via FME/rest if new users/projects start) then I can maybe somehow write an expression in survey 123 to mark when an id is used and grab the next lowest null valued id for the new site?

Its not pretty and not sure it will or can work, help me please!

My other issue is creating repeats for another form that is based on depth to and from. I need to be able to have a new repeat auto fill the from field using the previous to field (with the first starting at 0m) so first interval might be from 0m to 15m then from 15m to 17m from 17m to 28m etc. I have not found a way to do this either...

0 Kudos
10 Replies
DanHaynes123456
Occasional Contributor

Solution Found! I have managed to get this incrementing both on and offline by utilising fieldmaps and an arcade expression and then adding a hyperlink to my survey123 form in the pop up. So the workflow now is capture the point in fieldmaps to create the id (and location) then launch survey123 from fieldmaps. I have tested it offline with unsynced records in fieldmaps and it still passes the info through to survey123, the one thing to look out for is that all records need to be within your offline area. I tested with 2 separate areas and the second one restarted the count. However if I went to online and created the first point in the new area it continued the sequence offline. Below is the arcade expression I used in fieldmaps.

var projectValue = $feature["project"];

var geoCode = $feature["geologist"];

 

if (IsEmpty(projectValue) || IsEmpty(geoCode)) {

    return null;

}

 

if ($editcontext.editType == "UPDATE" && !IsEmpty($originalFeature["site_id"])) {

    return $originalFeature["site_id"];

}

 

var maxNum = 0;

 

for (var f in $layer) {

    var p = f["project"];

    var g = f["geologist"];

    var sid = f["site_id"];

 

    if (p == projectValue && g == geoCode && !IsEmpty(sid)) {

        if (Left(sid, Count(geoCode)) == geoCode) {

            var numText = Right(sid, 4);

            var num = Number(numText);

 

            if (!IsNan(num) && num > maxNum) {

                maxNum = num;

            }

        }

    }

}

 

var nextNum = maxNum + 1;

 

return geoCode + Text(nextNum, "0000");