0

i wanted to check a condition in DAML code but one value is a party and other is text and therefore getting ERROR:

• Couldn't match type ‘Party’ with ‘Text’ arising from a functional dependency between: constraint ‘DA.Internal.Record.HasField "owner" AccountInfo Text’ arising from a use of ‘DA.Internal.Record.getField’ instance ‘DA.Internal.Record.HasField "owner" AccountInfo Party’ at

if( login.party == "friend" || logout.party == "friend)
   userCId <- create Users with userType= "Friendly User",..
                            return (Right  userCId)
Shalabh Negi
  • 621
  • 7
  • 18

2 Answers2

6

As mentioned by Shayne you can use show (or partyToText) to convert to a Text. However, I don’t think this is the right way to approach this. Parties should be thought of as abstract identifiers and while the DAML sandbox allows you to use arbitrary strings, that is not true for other ledgers.

I would suggest that rather than hardcoding the check against a specific party literal, you extend the template with an additional field friend : Party and then compare against that. Then when you create the template you can set friend to "friend" on sandbox but you can also set it to something else.

So in the end you end up replacing

template C with
  …
  choice C : ()
    controller …
    do if login.party == "friend"
       …

with the following

template C with
  …
  friend : Party
  choice C : ()
    controller …
    do if login.party == friend
       …
cocreature
  • 801
  • 5
  • 5
-2

Calling show on your Party value should do the trick.

if show login.party == "friend" ...