Update User Status from System template

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
        name : Text
        user : Party
        signatory user 

// This choice will update User status
-{ choice UpdateStatus : ContractId User -}

type UserKey = (Party, Int)

 template User
        profileId : Int
        code : Optional Text
        name : Optional Text
        email: Optional Text
        status : Text
        user : Party
        systemUser : Party
    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.


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
      userContractChangeId: ContractId User
      user : Party
  controller user
      userContract <- fetch userContractToChangeId
      create userContract with 
                status =  if status ==  "Active" then "Archived" else "Active"
1 Like