How do I get a username into a table Using Attribute Rules?

798
2
Jump to solution
05-03-2022 11:10 AM
Labels (3)
phess_luckstone
New Contributor III

I created a log table in a file geodatabase. (Just my playground for right now).  In this log table I want to keep track of the type of edit done to my feature classes, the name of the feature class, date, username, objectid and globalid in the feature.  I have gotten all but one piece of the puzzle, the username.  Here is my code below:

return {
    "edit": [
    {
        "className": "Logs",
        "adds":        [{
                    "attributes": {"editType": $editContext.editType,
		#For Each Attribute Rule Put in Feature Class Name Below
                    "fclassName": "VA_SouthParcels",
                    "Date": Date(),
                    "fclass_GlobalID": $feature.GlobalID,
                    "fclassObjectID": $feature.objectid    }    }]
    }
    
]

}

 I have looked the documentation for the ArcGIS Arcade functions of GetUser, however I can't quite get it to work, any help would be appreciated.

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

I haven't worked with GetUser() yet, but you should be able to do something like this

var user = GetUser($featureSet)
if(!IsEmpty(user)) {
    user = user.username
}

 

In your FGDB, you won't have success with this, because

When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.

You could try turning on Editor Tracking, and then use the last_edited_user field:

var user = $feature.last_edited_user

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

I haven't worked with GetUser() yet, but you should be able to do something like this

var user = GetUser($featureSet)
if(!IsEmpty(user)) {
    user = user.username
}

 

In your FGDB, you won't have success with this, because

When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.

You could try turning on Editor Tracking, and then use the last_edited_user field:

var user = $feature.last_edited_user

 


Have a great day!
Johannes
phess_luckstone
New Contributor III

So since most of my layers have editor tracking enabled I modified that a little bit, and used this.

return {
    "edit": [
    {
        "className": "Logs",
        "adds":        [{
                    "attributes": {"editType": $editContext.editType,
                    "fclassName": "VA_SouthParcels",
                    "Date": Date(),
                    "User":$feature.last_edited_user,
                    "fclass_GlobalID": $feature.GlobalID,
                    "fclassObjectID": $feature.objectid    }    }]
    }
    
]

}

 

Which is nice because it even allows me to see if a user has deleted an item.

Thanks again.

0 Kudos