Skip to content
Discussions/App Development/How to get a list of Parties in a triggerForum ↗

How to get a list of Parties in a trigger

App Development5 posts215 views2 likesLast activity Jun 2022
AS
Ashok_RajOP
Jun 2022

In triggers, what is the best way to get all active parties on the ledger?

RI
rikotacards
Jun 2022

Someone correct me if I’m mistaken, but I don’t think you can get all active parties via triggers.
You can however

  1. create a User template, and provide a publicParty to the observer field.
  2. Get all active User contracts

The code in create-daml-app does this.

CO
cocreature
Jun 2022

@rikotacards is right, adding on top of that the party management endpoint requires admin claims. That means writing apps that should run for individual users is usually a bad idea since it means you need to give everyone admin claims.

AS
Ashok_Raj
Jun 2022

@cocreature I have created a alias template

Template Alias
   with 
        alice : Party
        bob : Party
   signatory alice
   observer bob

In the script, I have created the Alias contract and its visible in the results. Now i want to run a trigger and the trigger should be able to access the party alice. The trigger is going to be run by bob.

so here is the portion of my trigger, this is a support function i am using, I am looking at an auction happening, as soon as auction happens, i am querying all auction then calling the support function against each auction. Within the support function I want to access the party alice, I am facing issue accessing this. The


trigrSupFunc  : Auction.Auction ->  TriggerA () ()

trigSupFunc auc = do

  
    queryResults <- query @Alias.Market        -- Alias is imported properly  
    let markets = map snd queryResults
    debug $ "SD2 :"<> show (length queryResults)

markets contain all the market contracts, in this case there is only one so how do i access that contract out of the list and eventually access alice: party

I tried

markets.alice

and

let market = markets._1
market.alice

I also tried head, last to extract the contract out of the list

Also markets !! 0 , throws variable not in scope error

AS
Ashok_Raj
Jun 2022

missed to import DA.List, importing it solved the issue.

← Back to Discussions