1

I can't find any solution for my issue. Many I've tried doesn't work. Could someone help me?

I have a JSON like this:

{
"device": {
  "sdk_revision": "dev",
  "sdk_type": "android",
  "app_id": "0518101906",
  "app_version": "0.0.0"
},
"request": {}
}

in my request step in soapUI (RestProject).

I'd like to change the app_id value in this JSON, so in my groovy script I do:

import groovy.json.JsonSlurper

def today = new Date()
appId = today.format("MMddHHmmss")

def extractSelectionJson(String from) {
    def slurper = new JsonSlurper()
    def holderData = slurper.parseText(context.expand('${'+ from +'#Request}'))

appIdKey = holderData["device"]["app_id"]
appIdKey = appId
}

extractSelectionJson("SessionCreate")`

appId changed only locally, at my json request I have still "app_id": "0518101906" although I've tried setPropertyValue(), updateProperty() (maybe not right way).

1 Answer 1

2

For something simple like this, you can use just a one-liner:

{
  "device": {
    "sdk_revision": "dev",
    "sdk_type": "android",
    "app_id": "${=String.format('%tm%td%tH%tM%tS'
        , new Date()
        , new Date()
        , new Date()
        , new Date()
        , new Date())}",
    "app_version": "0.0.0"
  },
  "request": {}
}

If you need details for the String.format(), it is in the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.