Forum Discussion

Apoorva6's avatar
Apoorva6
Frequent Contributor
9 years ago
Solved

Need help in property transfer for Rest service

Hi All,

 

I have below response from which account1Number must be transferred to Next request body accountNumber. I used property transfer path giving $.invoiceNodeDetails[:0],account1Number  to $.userDetails[:0],accountNumber

 

Source: Request1 --Property as Response1

Target: Request2--property as Request2

 

I am getting error as error parsing, unexpected CDATA.

 

Response1

{
   "transactionDetails":    {
      "startRow": "1",
      "endRow": "400",
      "totalRow": "1",
      "timeZone": "EST"
   },
   "invoiceNodeDetails":    {
      "nodeLabel": "mx",
      "hierarchyPointId": "16760",
      "nodeStartDate": "20170419 01:40:35",
      "sequenceNumber": "982475",
      "updateDate": "20170419 01:40:35",
      "nodeCreateDate": "20170420 07:47:13",
      "account1Number": "8290000000682"
   },
   "orderDetails": {"serviceOrderNumber": "MX-EUAM-31734"}
}


Request2

{
      "customerDefinedGroupNodeDetails": {
         "parentInvoiceHierarchyPointId": "155346355",
         "startDate": "20170419 01:40:35",
         "customerDefinedGroupId": "000011",
         "customerAdminId": "",
         "label": "&cadmxprs&",
         "legacyIdTypeCode": "G"
      },
      "userDetails": {
         "userId": "DK246Q",
         "accountNumber": "8290000000682",
         "accountToNumber": "",
         "customerName": "WalGreen",
         "activity": "&Description provided by UI&"
      }
   }

  • Apoorva6,

    Alternatively, the Script Assertion (now Property Transfer step becomes obsolete) can be used for the first step.

     

    assert context.response, 'Response is empty or null'
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    context.testCase.setPropertyValue('ACCOUNT_NO', json.invoiceNodeDetails.account1Number.toString())
    

    In the second request use Property Transfer ${#TestCase#ACCOUNT_NO}

     

    i.e., "accountNumber": "${#TestCase#ACCOUNT_NO}",

10 Replies

  • nmrao's avatar
    nmrao
    Community Hero

    Apoorva6,

    Alternatively, the Script Assertion (now Property Transfer step becomes obsolete) can be used for the first step.

     

    assert context.response, 'Response is empty or null'
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    context.testCase.setPropertyValue('ACCOUNT_NO', json.invoiceNodeDetails.account1Number.toString())
    

    In the second request use Property Transfer ${#TestCase#ACCOUNT_NO}

     

    i.e., "accountNumber": "${#TestCase#ACCOUNT_NO}",

    • Apoorva6's avatar
      Apoorva6
      Frequent Contributor

      Thank you Paul and Rao. Will use the script and see, but also,

       

      I migrated to 5.3.0 version and see now JasonPath in property transfer, However I see transferred values are coming with square braces when transferred. Any idea why ?

       

      "accountNumber": ["8290000000717"]

       

      I am using $..invoiceNodeDetails[:1].account1Number at Source and $..userDetails[:1].accountNumber at target with both JasonPath

      • nmrao's avatar
        nmrao
        Community Hero
        It is not about square brackets. That is a list of accountNumbers.
  • PaulMS's avatar
    PaulMS
    Super Contributor

    Did you change the path language to JSON?

     

    JSONPath expression could be

    $.invoiceNodeDetails.account1Number

    or

    $..invoiceNodeDetails[0].account1Number

  • Apoorva6's avatar
    Apoorva6
    Frequent Contributor
    Hi Paul, Thanks for the reply. I am using 5.0.0 open source and i dont see language path in property transfer. Do i need to click anywhere to appear?
  • Apoorva6's avatar
    Apoorva6
    Frequent Contributor
    Hi Rao, ty. But is there a way to ensure not to get braces in request? We are not handling the request after property transfer due to braces.
    • nmrao's avatar
      nmrao
      Community Hero
      Well, let me admit that I am not good at jsonpath. If you are ok, use provided script assertion which is tested one.
    • nmrao's avatar
      nmrao
      Community Hero
      And more over one less test step in the test case if you go with Script assertion.