Select to view content in your preferred language

check value from inbox for readonly control.

75
2
yesterday
ElliottCarsonGF
New Contributor

Hi,

Is it possible to check if a record from the inbox has a value and if so, make it read only?

I've put this in the readonly column if(string-length(${value})>1,'yes',''), it throws a dependency error because it's looking for itself.

Any happy is appreciated.

Regards, 

Elliott

0 Kudos
2 Replies
Neal_t_k
Frequent Contributor

I don't think that is possible through survey123 itself. However, you could add a hidden field (yes,no) have it default set to no,  Have your value question in the read-only column set to ${<helper_field>}='yes'.  Then write a python script to post process the helper field based on the entry.

Something like this to get you started (I haven't tested it so it may need adjusting but should be close):

from arcgis.gis import GIS

portalURL = "https://www.arcgis.com"
username = "USERNAME"
password = "PASSWORD"
feature_item_id = "<ItemID>"

gis = GIS(portalURL, username, password)
feature_item = gis.content.get(feature_item_id)
layers = feature_item.layers + feature_item.tables
for layer in layers:
    features = layer.query(where="1=1", order_by_fields='objectid ASC').features
    for feat in features:
        gid = feat.get_value('globalid')
        value = feat.get_value('value')
        value_length = len(value) if value is not None else 0
        if value_length > 0:
            where_clause = f"globalid='{gid}'"            
            layer.calculate(where=where_clause, calc_expression={"field": 'helperfield', "value": 'yes'})

This will loop through all layers and tables, you can adjust to a specific one if needed.

edit: Changed this line: value_length = len(value)    to this:  value_length = len(value) if value is not None else 0

0 Kudos
ElliottCarsonGF
New Contributor

Thanks Neal,

Unfortunately, this is required to work offline. But I might try and see if a script could be utilised.

Regards,

Elliott

0 Kudos