Hello!
I have a code that works and that increments by 1 the last id of the same field.
if the "NewID" is 400, as soon as I add a new feature that code becomes 401 and so on.
the flow is this:
1. adds a new feature,
2. selects from a list the domain
and
3. the RefNumber is the result of the concatenation of the domain + the incremented ID calculated as below.
// Get the current feature's newID field value
var currentID = $feature.newID_web;
// Get the maximum value of the newID field from all features
var maxID = Max(FeatureSetByName($datastore, "Items", ["newID_web"]), "newID_web");
// If currentID is null, it means this feature needs a new ID
if (IsEmpty(currentID)) {
return maxID + 1;
}
// If currentID is already set, return the currentID
return currentID;
Now, I was asked to increment by domain, such as:
domain_w_001
domain_w_002
domain_t_001
domain_w_003
......
I got lost at this point.
Any idea on how to increment by domain?
Thanks!
I have used similar code for attribute rule posted here which finds the max number and increments its by one.
Then this post shows how I have modified that expression to increment by 'domain' (in my code, I use ID field).
This could give you idea(s) of one way to accomplish what you are after.
Basically, just filter the FS to only include the selected 'domain' value, then find the Max and increment and concatenate the prefix to the new ID and return. You would just need to redo the where clause to filter for $feature.Domain name whereas my code has a static value (DYCL%).
edit: to add another example here where this one uses the username to determine if it is passes the entire FS to the numarray or the filtered FS.
R_