Forum Discussion

fidzah's avatar
fidzah
Occasional Contributor
6 years ago

Getting array value from property transfer

Hi, The response that I get is something like this:   { "OperationResultType": "Success", "Code": 0, "Message": "", "Details": "", "ResultValue": { "Ids": [ ...
  • avidCoder's avatar
    6 years ago

    Hi Fidzah,

     

    There are 2 ways you can do it. Either you can write groovy script and store the values to the Properties Step.

     

    import groovy.json.JsonSlurper
    def json = '''{
    "OperationResultType": "Success", "Code": 0, "Message": "", "Details": "", "ResultValue": { "Ids": [ "177", "178" ], "Errors": [ "", "" ] } }''' def jsonSlurper = new JsonSlurper() def obj = jsonSlurper.parseText(json) log.info obj.ResultValue.Ids testRunner.testCase.getTestStepByName("Properties").setPropertyValue("ID", obj.ResultValue.Ids)

    Else you can use PropertyTransfer step to write the xpath for the json path :-

    $.ResultValue.Ids

    You can use this website for json path evaluator - JSONPath Evaluator

     

  • fidzah's avatar
    fidzah
    6 years ago

    Thanks, this can be work if using groovy script.

    But I just want to retrieve it from the project.

    What I did is:  

    1 created 2 IDs from Property Transfer:


    sendID - $.ResultValue.BackupJobIds[0]
    sendID2 - $.ResultValue.BackupJobIds[1]

     

    NOTE: at the bottom of the PropertyTransfer screen, tick
    Entitize transferred values(s) - as the original response giving the value [[123]], so I need to get it as [123]