Select to view content in your preferred language

check value from inbox for readonly control.

165
3
Wednesday
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
3 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
Neal_t_k
Frequent Contributor

@ElliottCarsonGF If post processing won't work,this might.  Instead of making it read-only you can make it not visible  using the body::esri:visible field and base that on a calculated answer in a helper question.  You can add a note field in place of the read-only to show what the answer is. After testing, you can hide the helper field so once a user answers the question it is inaccessible.  Kind of hard to explain, attached is an example.  

Or, You could base the read-only status on providing answers on a subsequent question/s.  The limitations would be a user could un-answer the subsequent questions and make it not read-only or if they skipped ahead, the read-only status could be triggered prior to answering that question.

 

 

0 Kudos