Select to view content in your preferred language

Constraint Rule, Arcade, Lookup table value in dictionary

880
2
Jump to solution
06-09-2023 12:52 PM
ebcdm
by
Emerging Contributor

I'm having issues creating a Constraint rule that checks whether a value exists within an array. These arrays will define whether or not the features can be edited by the user if they have a matching group/key to the owner field in the table. 

The issue is that when passing the owner value from the feature class table, to the object, to grab the correct array  of users, the attribute rule will not save and errors out saying that it cannot find the field. However, it will pass debugging using Console() within the Arcade editor window. 

It will also work if the owner value is hard coded to grab the correct array (i.e. var array1 = partners['partner2'];). But will not work when that value is passed in a variable.

Has anyone else seen any issues around these topics setting up attribute rules?

 

 

 

var partners = Dictionary(
    'partner1', ["user1", "user2"], 
    'partner2', ["user5", "user4"])

// Get currently logged in user
var userInfo = getUser().username;

// Get the "partner" value of the currently edited feature
var featureDataOwner = Replace($feature.DataOwner, ' ', ''); //theres sometimes spaces in the feature class table
var array1 = partners[featureDataOwner];

Console(userInfo)
Console(featureDataOwner)
Console(array1)

if (Includes(array1, userInfo)) return true

return false

 

 

 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

Does it work if you insert this after line 9?

// check if the DataOwner is included in the dictionary
if(!HasKey(partners, featureDataOwner)) return false

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Alum

Does it work if you insert this after line 9?

// check if the DataOwner is included in the dictionary
if(!HasKey(partners, featureDataOwner)) return false

Have a great day!
Johannes
ebcdm
by
Emerging Contributor

It appears that it is working with that. Thank you!

0 Kudos