cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to set value in json object in dynatrace pre script method

nitinkumar
Newcomer


var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);

Let's say I have this JSON below and I want to change IDToken3 value FROM "skip-input-886" to "test" and put back the same object in jsonData so I can send it in api.setValue("jsonData ", jsonData );

How can I change value of IDToken3 in this JSON via POST Execution Script

 

{
"testid": "testing",
"callbacks1": [
{
"type": "TextOutputCallback",
"output": [
{
"name": "message",
"value": "message-886"
},
{
"name": "messageType",
"value": "0"
}
]
},
{
"type": "ConfirmationCallback",
"output": [
{
"name": "prompt",
"value": ""
},
{
"name": "messageType",
"value": 0
},
{
"name": "options",
"value": [
"Set up"
]
},
{
"name": "optionType",
"value": -1
},
{
"name": "defaultOption",
"value": 0
}
],
"input": [
{
"name": "IDToken2",
"value": 0
}
]
},
{
"type": "HiddenValueCallback",
"output": [
{
"name": "value",
"value": "false"
},
{
"name": "id",
"value": "skip-input-886"
}
],
"input": [
{
"name": "IDToken3",
"value": "skip-input-886"
}
]
}
]
}

1 REPLY 1

nitinkumar
Newcomer

resolved now,anyone need solution , find below for (i = 0; i<jsonData.callbacks.length;i++)
{
var jsonObj=jsonData.callbacks[i];
// console.log(jsonObj);
if(jsonData.callbacks[i].type=="testtest"){
if(jsonData.callbacks[i].input[0] != null && jsonData.callbacks[i].input[0].name=="IDToken"){
jsonData.callbacks[i].input[0].value="test";

}
}
}
api.setValue("req_body", jsonData);

Featured Posts