How to fetch a value from one template and paste it another template in scenario
- nikhilreddyOP
module Final where import Daml.Script data Agent = Agent with name : Text email : Text phone_number : Text regulator : Party deriving (Eq, Show) template Cases with casenum : Text timestamp : Text claiment : Agent respondent : Agent casetype : Text regulator : Party where signatory regulator -- key (email,name) : (Text,Text) -- maintainer key._1 choice Updatecase : ContractId Cases with ncasenum : Text ntimestamp : Text nclaiment : Agent nrespondent : Agent ncasetype : Text controller regulator do create this with casenum = ncasenum timestamp = ntimestamp claiment = nclaiment respondent = nrespondent casetype = ncasetype template Document with regulator : Party caseid : Text doctype : Text docname : Text dochash : Text timestamp : Text uploadedby : Agent where signatory regulator choice Updatedoc : ContractId Document with ndoctype : Text ndocname : Text ndochash : Text ntimestamp : Text nuploadedby : Agent controller regulator do create this with doctype = ndoctype docname = ndocname dochash = ndochash timestamp = ntimestamp uploadedby = nuploadedby setup = script do alice <- allocatePartyWithHint "Alice" (PartyIdHint "Alice") -- submit alice do -- createCmd Asset with -- respondent = alice -- claiment = alice -- casenum = "7890" -- filename = "Text" -- filehash = "Text" -- timestamp = "Text" -- uploadedby = "Text" cases<- submit alice do createCmd Cases with casenum = "124" timestamp = "Time" claiment = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice respondent = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice casetype = "Text" regulator = alice submit alice do createCmd Document with regulator = alice caseid = "124" doctype = "agreement" docname = "testcases" dochash = "2azxwe34qwdaw1234raasr" timestamp = "Text" uploadedby = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = aliceIn Scenario How can add Real Timestamp for cases contract ( line number 100)
In Scenarios How can I fetch the caseid(Documents Template) value which is equal to casenum( Cases Template)
- cocreature
To get the time, change the type of the field from
TexttoTimeand then use something liketime <- getTime cases<- submit alice do createCmd Cases with casenum = "124" timestamp = time claiment = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice respondent = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice casetype = "Text" regulator = aliceNote that this fills in the timestamp on the client side. You could also fill it in in a choice that you call via
createAndExerciseCmdin which case it will be selected on the participant.For your second question, you could use
queryto fetch allDocumentcontracts and then filter to the ones with the corresponding case id. Something like this:allDocuments <- query @Document alice let filteredDocs = filter (\d -> d.caseid == "124") allDocumentsYou might want to consider using a contract key for the case id here in which case you could use
queryContractKeyto fetch by case id instead of fetching all contracts and then filtering. - nikhilreddy
cocreature:time <- getTimecan you please explain the second part, I am unable to understand.
I want to fetch the casenum value and allocate it to the case Id in script results. - nikhilreddy
Part two of my question is
template Cases with casenum : Text timestamp : Time claiment : Agent respondent : Agent casetype : Text regulator : Party where signatory regulator key regulator : Party maintainer key template Document with regulator : Party caseid : Cases.casenum(this caseid should equal to casenum from Cases Documnet) doctype : Text docname : Cases dochash : Text timestamp : Time uploadedby : Agent where signatory regulator key regulator : Party maintainer keyHow can I equate the casenum from Documents Template to caseid to Cases Template, Because both case Id and Casenum are same!!
- cocreature 1
I’m not sure I understand what you mean by
equatebut you can do something like this:casesCid <- submit alice do createCmd Cases with casenum = "124" timestamp = "Time" claiment = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice respondent = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice casetype = "Text" regulator = alice Some cases <- queryContractId alice casesCid submit alice do createCmd Document with regulator = alice caseid = cases.casenum doctype = "agreement" docname = "testcases" dochash = "2azxwe34qwdaw1234raasr" timestamp = "Text" uploadedby = Agent with name = "Nikhil" email = "nikhil@gmail.com" phone_number = "8323832938" regulator = alice