Populate attribute value with the value of other fields in same feature service
I have an editable feature service for address points. The attributes included in this layer include fields for each address element individually as well as a field for the full address. I am trying to figure out a way, either by add new feature using feature template or creating a workflow, that the user can enter the values for address number, road name, prefix, etc and the field 'FullAddress' can be automatically populated by concatenating the inputs from the other fields.
I started a workflow where I queried to select a single address point and returned all fields. I then take that query result and do the following assign.
Value (InAgruement):
query_result.Features(0).Attributes("PREADDRNUM,ADDRNUM,ADDRNUMSUF,FULLNAME,UNITTYPE,UNITID").ToString
To (Out Arguement):
strFullAddr
Am I on the right track with this method? If so, how can I take the strFullAddr string and pass it into the field for "FULLADDR" in my feature service.
Thanks
0
-
Hi Lauren,
If you want to concatenate a bunch of strings together, then you would have to split up your Value input to this:
string.Format("{0}, {1}, {2}, {3}, {4}, {5}", query_result.Features(0).Attributes("PREADDRNUM"), query_result.Features(0).Attributes("ADDRNUM"), query_result.Features(0).Attributes("ADDRNUMSUF"), query_result.Features(0).Attributes("FULLNAME"), query_result.Features(0).Attributes("UNITTYPE"), query_result.Features(0).Attributes("UNITID"))
The Attributes method does not take this many columns at once so it will error out.
After you have generated the strFullAddr string, you can assign it to a feature by:
1. Querying for the feature you want to add the full address to
2. use an Assign activity to assign the new value to the feature like this:
To = featureSet.Features.First().Attributes("FULLADDR")
Value = strFullAddr
3. Then use the UpdateFeatures activity to commit the changes.
If you want more information, this code gallery sample demonstrates on how to update features:
https://support.geocortex.com/essentialsGSCCodeGallery?sub-nav=codegall&main-nav=essentials&#!/feedtype=SINGLE_ARTICLE_DETAIL&criteria=BESTANSWERS&id=kA4600000004EWUCA2
I hope this helps.
Regards,
Carmen0 -
Thank you, this helps a lot. 0 -
I got the concatenate to work and update the feature to commit the changes. Is there a way to account for fields that have a null value without adding a space in the concatenated string. For example, if the address does not have a suffix, I don't want a space to be added where that value would go. Any suggestions? 0 -
IF(fs.Feature(i).Attributes("fieldname") is Nothing,"",fs.Feature(i).Attributes("fieldname").ToString())0 -
Hi Lauren,
I would do what Tom has suggested and include an IF activity per parameter to catch whether the value is NULL or empty. If you have 6 parameters, then you would have 6 IF activities. The condition would be something like this:
query_result.Features(0).Attributes("PREADDRNUM").ToString.IsNullOrEmpty
Then: leave this section empty and it would allow the workflow to just continue
Else: Use an assign activity here wherestrFullAddr = strFullAddr + query_result.Features(0).Attributes("PREADDRNUM").ToString
I hope this helps.
Regards,
Carmen0 -
I set up each of the 6 if statements as follows...
Condition: query_result.Features(0).Attributes("ADDRNUM").ToString.IsNullOrEmpty
Then: empty
Else: Assign activity
To: strFullAddr
Value: strFullAddr + query_result.Features(0).Attributes("PREADDRNUM").ToString
I am getting an error from my If statement that the "Object Reference is not set to instance of an object". I am having some trouble figuring out how to fix this. My initial thought was that is has something to do with the Attributes("ADDRNUM") portion of the condition?0 -
Hi Lauren,
If that's the case then I would try replacing all your IF activities to using the TRY/CATCH activity. What that error means is we are trying to assign it a value that does not exist. So if the query_result.Features(0).Attributes("ADDRNUM") produces a NULL value, then we cannot convert it into a string to see if it is empty or not. That is what I think is causing the error. The try/catch activity would eliminate that issue.
Regards,
Carmen0 -
Perfect, that makes sense. Thanks again. 0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
8 kommentarer