irfan baba
irfan baba

Reputation: 21

DAML :- Am unable to set party as observer from another template of its array argument, please help on the same

I am trying to set a party as observer, with that observer argument taking from another template argument which defined as array. Please find the below snippet of my code:

template Roles
  with
      subscriber: Party
      signeddate : Time
  where
    signatory subscriber
template Deal
  with
    deal: Users_Deal
    actor : [Roles]
  where
    signatory deal.agent
    observer actor.subscriber     <---  here I am getting an error

template Users_Deal
  with
    dealId: Text
    agent: Party

Upvotes: 1

Views: 72

Answers (1)

cocreature
cocreature

Reputation: 811

If you look at the error it will look something like this

No instance for (DA.Internal.Record.HasField "subscriber" [Roles] a0)
arising from a use of ‘DA.Internal.Record.getField’

What the compiler is trying to say here is that the type [Roles] does not have a field called subscriber. This is correct. Roles has a field but [Roles] is a list of those types.

What you can do is to get the subscriber of each Roles (you might want to call it Role instead of Roles) in the list and set all of those as observers. You can do that by calling map on the actor list:

template Deal
  with
    deal: Users_Deal
    actor : [Roles]
  where 
    signatory deal.agent
    observer map (\a -> a.subscriber) actor

Upvotes: 2

Related Questions