Skip to main content
chrisg0006
December 18, 2024
Solved

Error "Could not cast from User to User."

  • December 18, 2024
  • 8 replies
  • 0 views

I have in my Record Types two fields, Created By and Modified By.  Both of those data types are set to user.

  They are also linked to the Appian User.

I have a Process Model kicked off by a Portal.  I would like to get the initiator of the process to be saved into one of these two fields.  I have used:

  1. pp!initiator - From the Process Properties
  2. pv!processUser - This is a process variable of User type that I created by saving the pp!initiator to pv!processUser
  3. touser(pp!initiator)
  4. touser{pv!processUser)
  5. "PMSO_ServiceAccount) - the text value of the portal User Name for Service Account.  I verified that the User Name does indeed exist and is the account that runs the portal.
  6. touser("PMSO_ServiceAccount")

In all of these cases, I got the process error (Could not cast from User to User. Details: CastInvalid) (Data Outputs)!!!  This works in all other areas of the application, just not in the process model kicked off by the Portal.

Best answer by stefanhelzle0001

That's a good solution. Instead of that cast and typeof construct, you can just do a tostring().

8 replies

stefanhelzle0001
December 18, 2024

Not sure why you want to store the initiator? It will always be that service account.

That service account is a different type of user and it could be that when that process is initiated by that same account, that user does not have permission to do that cast. This is mostly guessing on my side though.

chrisg0006
December 18, 2024

The process I am using can be kicked off by the Portal as well as by the office personnel from the speaker interface.  I thought I would capture both.  The service account has explicit security access to the process model and is in the administration group for the application.

You are probably right.  I have the same logic other places in the process and it works if I initiate the process with my ID (i.e. from the administration interface).

chrisg0006
December 18, 2024

So to get around the service account and still get the user from the administration screen, I used the following logic to load the pv!processUser.

if(
    cast(typeof("abc"), pp!initiator)="PMSO_ServiceAccount",
    null,
    pp!initiator
)

mathieud0001
December 19, 2024

A workaround could be to wrap the startProcess in an API rather than calling it directly from the portal.