Skip to content
Discussions/App Development/Can we specified the authority in field's level?Forum ↗

Can we specified the authority in field's level?

App Development13 posts248 views16 likesLast activity Aug 2021
NR
nr185OP
Jul 2021

Hi DAML’ers,
I’m currently trying to learn DAML by developing such a card activity management system. I have a template, let’s say Card which consists of cardType, cardStatus, ExpiredDate, and PINOffet. However, I need to restrict the PINOfset field, even signatory is not allowed to see it.
How to do that in DAML? is there any mechanism to restrict the authority in field’s level?

Your feedback very useful for me.
Thank you :slight_smile:

CO
cocreature
Jul 2021

Hi @nr185,
if I understand you correctly you want to limit visibility of specific fields instead of having visibility be defined at the level of contracts.

Currently that is not possible. Either a party sees a contract and all fields in it or it doesn’t see the contract at all.

So if you want to limit visibility of specific fields, you need to split the contract into different ones with different fields and then have different visibility on those contracts.

NR
nr185
Jul 2021

Hi @cocreature
Thank you for your feedback!
Yes, you are correct. That’s what I mean.

NR
nr185
Jul 2021

Hi DAML ers,

I am currently, trying to create a daml program about card activity management. In short, this system is about linking card number with the account number, activate the card (update card status from not active to active), and once the activation is success, it will update count of the card stock in card Inventory, will become count -1.

Hence, I create 3 templates : CardInventory, Card, and Account.

Now I get an error as shown in this pic.
This is from the Card Template. I’m confused why this error happened.

Your feedback will be very helpful for me.
Thanks a lot.

DR
drsk
Jul 2021

Looks like you just have to assign values to the fields customerService, cardInv and branch when you create the card. Just like you did with cardNumber, cardStatus and lastUpdate. It would be helpful if you’d share the definition of the Card template.

NR
nr185
Jul 2021

Yes,
This is the complete version for the card template.

template CardInventory
  with
    branch : Text
    count : Int
    staff : Party
    auditor : [Party]
    customer : Party
  where
    signatory staff 
    observer auditor

template Card
  with
    cardNumber : Text
    cardStatus : Text
    lastUpdate : Date
    customerService : Party
    cardInv : CardInventory
    branch : Text
  where
    signatory customerService, customer
    observer cardInv.customerService, cardInv.auditor

    preconsuming choice ActivationCard : ContractId Card
      with
        newCard : Text
      controller customerService 
        do
          cardContractId <- lookupByKey @Card(cardNumber, cardStatus)
          now <- getTime 
          assertMsg "This card status must be Not Active (NA)" (cardStatus /= "NA")
          assertMsg "Update card stock in branch" (branch /= cardInv.branch)   
          create Card with
            cardNumber = newCard
            cardStatus = "AA"
            lastUpdate = now

Thank you for your help and sorry for the very basic question. I need to fully understand about this.

AN
anthony
Jul 2021

Hey @nr185 welcome to the forum!

If your intent with the ActivationCard choice is to archive the current contract and replace it with the activated version you can do create this with instead of create Card with. When you do this you only need to update the fields you want to and the rest will keep their previous values.

Also the choice is currently preconsuming and you might have to remove that.

Also some other notes:

  • I noticed your Card template has a customer signatory but that’s not a field on Card perhaps you intended cardInv.customer?
  • assertMsg "This card status must be Not Active (NA)" (cardStatus /= "NA") from the error message this seems to suggest that you want to do cardStatus == "NA"
NR
nr185
Aug 2021

Hi @anthony, thank you for your feedback. Very helpfull :slight_smile:

NR
nr185
Aug 2021

Hi all, good morning!

By the way I stuck with this problem. I’m sure this must be a simple mistake. But honestly, I am still confusing where is the mistake. “parse error (possibly incorrect indentation or mismatched brackets)”

GA
Gary_Verhaegen
Aug 2021

You shouldn’t have a let directly after a with. Try just deleting that line (between CardInventory with and branch).

NR
nr185
Aug 2021

Many thanks for your response!
By the way, how to assign “Date” type in DAML?
I try this dob = 09-12-2012 and it’s error.

GA
Gary_Verhaegen
Aug 2021

Dates do not have a literal representation in Daml, so you have to “build” them by calling functions on other data types. Here’s a full, self-contained example:

module Main where

import Daml.Script
import DA.Date

test : Script ()
test = script do
  let today = DA.Date.fromGregorian (2021, DA.Date.Aug, 4)
  debug $ "Today is " <> show today
  return ()

The debug call outputs:

Today is 2021-08-04
NR
nr185
Aug 2021

Ooh I see. Thank you for your help! :slight_smile:

← Back to Discussions