Ask a Question

Get ID dynamically and do a property transfer ?

SOLVED
mpw83
Contributor

Get ID dynamically and do a property transfer ?

I have a REST request which returns IDs. It's cannot be guaranteed about the number of records. Sometimes the number of ID's is 2 and sometimes more than 2 (e.g. 4). I need to get these ID's and do a property transfer into Test Case Properties.
Response JSON is similar to 

{
   "totalSize" : 1,
   "done" : true,
   "records" : [
      {
         "attributes" : {
            "type" : "Account__c",
            "url" : "/services/data/v39.0/sobjects/Account__c/a4X0p0000001LWLEA2"
         },
         "Id" : "a4X0p0000001LWLEA2",
         "peer__Schedule__r" : {
            "totalSize" : 4,
            "done" : true,
            "records" : [
               {
                  "Id" : "a680p0000000QHxAAM"
               },
               {
                  "Id" : "a680p0000000QHyAAM"
               },
               {
                  "Id" : "a680p0000000QHzAAM"
               },
               {
                 "Id" : "a680p0000000QI0AAM"
               }
            ]
         }
      }
   ]
}

How I can get these ID's dynamically? Help much appreciated. Thanks   

1 ACCEPTED SOLUTION

Accepted Solutions
HimanshuTayal
Community Hero

Re: Get ID dynamically and do a property transfer ?

Hi @mpw83 ,

 

In that case you can use groovy script and use jsonSlurper, use the below groovy code.

import groovy.json.JsonSlurper
def ResponseMessage = testRunner.testCase.getTestStepByName("Name of your Test Step").getPropertyValue("response");
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
	
mainRecord =  jsonSlurper.records
for(i=0;i<mainRecord.size();i++){
	recordsID = mainRecord[i].peer__Schedule__r.records;
	for(j=0;j<recordsID.size();j++){
		log.info recordsID.Id[j]
	}
}

Hope it will help you i n resolving your problem.

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
HimanshuTayal
Community Hero

Re: Get ID dynamically and do a property transfer ?

Hi @mpw83 ,

 

In that case you can use groovy script and use jsonSlurper, use the below groovy code.

import groovy.json.JsonSlurper
def ResponseMessage = testRunner.testCase.getTestStepByName("Name of your Test Step").getPropertyValue("response");
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
	
mainRecord =  jsonSlurper.records
for(i=0;i<mainRecord.size();i++){
	recordsID = mainRecord[i].peer__Schedule__r.records;
	for(j=0;j<recordsID.size();j++){
		log.info recordsID.Id[j]
	}
}

Hope it will help you i n resolving your problem.

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

mpw83
Contributor

Re: Get ID dynamically and do a property transfer ?

@HimanshuTayal  , Thanks for sharing your code. I will use that to solve my problem. 

mpw83
Contributor

Re: Get ID dynamically and do a property transfer ?

@HimanshuTayal Thanks for sharing your code. I will use that to solve my problem. 

cancel
Showing results for 
Search instead for 
Did you mean: