Casting from JSON to Record fails on CastInvalidCould not cast from Dictionary to User.

Certified Lead Developer

Problem: When applying a!toJson on a record type, record fields of type user will be converted to JSON objects. When casting the JSON back to record type, it fails to convert the user object (dictionary) to User type with error: CastInvalidCould not cast from Dictionary to User. 

Example

  • recordType!Test(id: 1, createdBy: "user 1") - createdBy record field is USER type
  • a!toJson on the above will return a json object with nested createdBy object: {"id"=1, "createdBy": {"id":"username1"}}
  • a!fromJson returns a dictionary with createdBy as a nested dictionary: {id:1, createdBy:{id: "username1"}}
  • casting to recordType!Test will throw error CastInvalidCould not cast from Dictionary to User.

Changing the record field type from user to text would eliminate issues in JSON conversion, but it takes away the ability to use record security rules by user fields. Another workaround is to flatten out all record fields that are of type user and convert it to the username string. 

Does Appian have a solution for this?  

  Discussion posts and replies are publicly visible