Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

[Help] Parameterize Object Names in JSON Message Responder

awalls
awalls Posts: 15

Hi,

I am trying to parameterize the object name in a JSON message responder response as shown in the following image:

If I switch to literal input mode and use the ${} Syntax, I just get the the variable name sent back in the response. (Yes, data source correlation is set up for this example and the responder can access values inside of Data REPO)

Example Parameterized Object Name

Example Response of Parameterized Object Name

Thanks

Comments

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    I notice that there is a field named "ParasoftColumn" in the original literal payload. Is the responder using a Data Repository Data Source?

  • awalls
    awalls Posts: 15

    Hi William,

    Yes the responder is using a Data Repository Data Source, this is where the parameterized values are coming from

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    When using the data repository the columns often indicate hierarchy rather than actual data values. In this case, the "ParasoftColumn" being set to "cmMacAddress" means that in the data repository there is a list field that is controlling how many occurrences of the JSON object should be written. So using that to parameterize a field name is not going to work because there is no text data value associated with that column.

    I tested that when not using a data repository data source I was able to parameterize the field name to a column name.

    Do you have to use a data repository for this use case or can a table data source be used instead? If you have to use a data repository data source look for a column on the parent record that referss the "cmMacAddress" field. It may be possible to use a data column on the parent record to parameterize the field name.

  • awalls
    awalls Posts: 15
    edited November 2020

    Hi,

    Even if I use a JSON data bank to get the value coming in from the request, I'm still not able to parameterize the object name being sent back in the response:

    In this case, the data repo is not being used to get the mac values and the variable name is still being sent back as the response instead of the value stored in it. Note: Both the object name & DeviceID is using the same variable from the JSON data bank, but only deviceID is being parameterized and not the object name

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    Would you be able to share an example pva file? When I set up an example using data banks it works, the field gets parameterized. What version of Virtualize are you using?

  • awalls
    awalls Posts: 15

    Hi,

    I believe I'm using version 9.10

    I've attached an example pva file to this as well.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    I was able to reproduce what you are seeing. It seems when the data repository is in use then the field name does not get parameterized. You will probably have to remove the data repository data source entirely to be able to get the parameterization of the field name to work.

  • awalls
    awalls Posts: 15

    Hi,

    Do you know of any other workaround for this? Other fields make use of information in Data Repo, removing data source entirely pretty much breaks my other use cases

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,

    One idea would be to rename the "reqcmMacAddress" field using an extension tool. A script could do a simple string replacement on the text in the outgoing response using the value from the data bank.

    To do this attach an extension tool to the outgoing response. Get the desired value from the data bank and then do a string replace. The method should then return the newly modified response message.

    See this documentation for how to access a data bank value from a script
    https://docs.parasoft.com/display/SOAVIRT9103CTP310/Extensibility+and+Scripting+Basics#ExtensibilityandScriptingBasics-AccessingDataSourcesfromScripts

  • awalls
    awalls Posts: 15

    Hi William,

    I'm looking through the documentation & I'm not seeing how exactly to to get the response String to use a string replace on, also I will need to know how to send the newly replaced string as a response, any help on this?

    Thanks

  • awalls
    awalls Posts: 15

    Hi William,

    I'm looking through the documentation & I'm not seeing how exactly to to get the response String to use a string replace on, also I will need to know how to send the newly replaced string as a response, any help on this?

    Thanks

  • awalls
    awalls Posts: 15

    I figured it out, thanks for all of the help

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Glad to hear you were able to figure it out! :)