# How to fetch a value from one template and paste it another template in scenario

**URL:** <https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825>\
**Category:** App Development\
**Tags:** daml, scenario\
**Created:** [January 31, 2022, 4:33pm UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825 "2022-01-31T16:33:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhilreddy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nikhilreddy/32/2248_2.png) [@nikhilreddy](https://forum.canton.network/u/nikhilreddy)\
**Post date:** [January 31, 2022, 4:33pm UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825/1 "2022-01-31T16:33:01Z")

</div>

```haskell
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 = alice

```

In 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)

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [January 31, 2022, 6:25pm UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825/2 "2022-01-31T18:25:05Z")

</div>

To get the time, change the type of the field from `Text` to `Time` and then use something like

```haskell
  time <- 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 = alice

```

Note that this fills in the timestamp on the client side. You could also fill it in in a choice that you call via `createAndExerciseCmd` in which case it will be selected on the participant.

For your second question, you could use `query` to fetch all `Document` contracts and then filter to the ones with the corresponding case id. Something like this:

```haskell
allDocuments <- query @Document alice
let filteredDocs = filter (\d -> d.caseid == "124") allDocuments

```

You might want to consider using a [contract key](https://docs.daml.com/daml/reference/contract-keys.html) for the case id here in which case you could use `queryContractKey` to fetch by case id instead of fetching all contracts and then filtering.

---

<div class="post-metadata">

**Author:** ![nikhilreddy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nikhilreddy/32/2248_2.png) [@nikhilreddy](https://forum.canton.network/u/nikhilreddy)\
**Post date:** [January 31, 2022, 9:36pm UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825/3 "2022-01-31T21:36:41Z")

</div>

> [@cocreature](#):
>
> ` time <- getTime`

can 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.

---

<div class="post-metadata">

**Author:** ![nikhilreddy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nikhilreddy/32/2248_2.png) [@nikhilreddy](https://forum.canton.network/u/nikhilreddy)\
**Post date:** [January 31, 2022, 10:58pm UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825/4 "2022-01-31T22:58:23Z")

</div>

Part two of my question is

```haskell
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 key

```

How can I equate the casenum from Documents Template to caseid to Cases Template, Because both case Id and Casenum are same!!

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [February 1, 2022, 7:01am UTC](https://forum.canton.network/t/how-to-fetch-a-value-from-one-template-and-paste-it-another-template-in-scenario/3825/5 "2022-02-01T07:01:37Z")

</div>

I’m not sure I understand what you mean by `equate` but you can do something like this:

```haskell
  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

```
