I am trying to update user record from System template, what I want is first retrieved the old record and archived the current User contract and create new one with updated status and every thing remain same.
here is my sample template
template SystemUser
with
name : Text
user : Party
where
signatory user
// This choice will update User status
-{ choice UpdateStatus : ContractId User -}
type UserKey = (Party, Int)
template User
with
profileId : Int
code : Optional Text
name : Optional Text
email: Optional Text
status : Text
user : Party
systemUser : Party
where
signatory [systemUser , user]
key ( user, profileId ) : Userkey
maintainer key._1
1 Like
Hey @Muhammad_Moiz. Could you show us the choice you wrote and what the problem is? Any error messages or unexpected behavior would be helpful.
Without some idea of where itâs going wrong, itâs very hard to know how to help.
2 Likes
This is my sample code to update status from SystemUser template but it show me error on âthisâ key word
Couldnât match type âSystemUserâ with âUserâ
Expected type: Update (ContractId User)
Actual type: Update (ContractId SystemUser)
choice UpdateStatus : ContractId User
controller user
do create this with
status = if status == "Active" then "Archived" else "Active"
1 Like
Within the body of a template this
refers to an instance of that template. In your case you are writing the choice UpdateStatus
inside the body of a SystemUser
template (which you can see from the âActual type: âŚâ error message), but the returned element of that choice is a User
.
If you leave this choice within the SystemUser template, you need to pass in a ContractId User
as an argument to that the choice:
choice UpdateStatus : ContractId User
with
userContractChangeId: ContractId User
user : Party
controller user
do
userContract <- fetch userContractToChangeId
create userContract with
status = if status == "Active" then "Archived" else "Active"
1 Like