Skip to content
CCPEDIAby Unity Nodes
App Development

Update User Status from System template

4 posts355 views5 likesLast activity Oct 2020

  1. Muhammad_MoizOP 1

    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
  2. SamirTalwar 2

    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.

  3. Muhammad_Moiz 1

    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"
  4. Leonid_Rozenberg 1

    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"