Service Virtualization

 View Only
  • 1.  Reuse of a variable in VSI Match Script

    Posted Apr 27, 2021 08:14 AM
    Hi, 

    After some operations in my VSI, I save a value in a variable using match script in VSI. I want to use that variable in my response file. How to use it?

    Ex: If I store var a = 20 in match script, and then in my response I tried like {{a}}. But it doesnt work. 

    Also, I tried with testExec.setStateValue("a",20) in my VSI match script. But this also doesnt wiork. 

    Can anyone help?




    ------------------------------
    Geetha
    CTS
    ------------------------------


  • 2.  RE: Reuse of a variable in VSI Match Script

    Posted Apr 27, 2021 09:53 AM
    Edited by Vaibhav Jain Apr 27, 2021 09:55 AM
    Hi Geetha,

    You can set the value in VSM to use it in response as variable instead of configuring it in VSI's match script section.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 3.  RE: Reuse of a variable in VSI Match Script

    Posted Apr 27, 2021 09:58 AM
    HI Vaibhav, 

    My request file doesn't have this info. I'm doing some calculations in VSI match script and saving that value in a variable. I need to use that variable in my response. How to configure that in VSM ?

    Can you elaborately tell me.

    ------------------------------
    CTS
    ------------------------------



  • 4.  RE: Reuse of a variable in VSI Match Script

    Posted Apr 27, 2021 10:16 AM
    Edited by Vaibhav Jain Apr 27, 2021 10:20 AM
    Hi Geetha,

    I am able to get the values set in VSI script in response (Not sure what exactly is wrongly configured in your scenario). Below is what i used:

    --> testing variable is already defined in my config file
    --> I defined a variable named y in my matchscript and assigned a value
    --> I have assigned a value in a variable named "x"



    For all 3 scenarios, i am able to use them as variable in my response. Please check once.

    Response configured in VSI:


    Response received on execution of call:


    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 5.  RE: Reuse of a variable in VSI Match Script

    Posted May 03, 2021 05:28 AM
    Hi Vaibhav, 

    Even I tried the same mentioned above but couldn't achieve it. 





    Output:


    ------------------------------
    CTS
    ------------------------------



  • 6.  RE: Reuse of a variable in VSI Match Script

    Posted May 03, 2021 05:36 AM
    Hi Geetha,

    Try setting the value outside if block once as it might be possible that the if condition is not getting fulfilled.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 7.  RE: Reuse of a variable in VSI Match Script

    Posted May 03, 2021 05:59 AM
    Hi Vaibhav, 

    It worked fine when used outside the block. But I need within the loop as my operations are done within the loop. So I can assign the value ony when it is within the loop. Is there any other way to achieve the same ? 

    Any way to identify a particular file from a list of files using regular expression. Actually I'm trying to do the below:

    I have a list of files in a folder naming:

    transref_guid_Geetha_123
    transref_guid_Geetha_124
    transref_guid_Geetha_345

    My request contains only the transref guid which I can identify uniquely. now among the three files using transrefguid and name I want to identify the file uniquely and there can any numbers after the name. I wanna store that number and send in response file. Is there anyway to proceed this without looping? Any regular expression can be used?

    ------------------------------
    CTS
    ------------------------------



  • 8.  RE: Reuse of a variable in VSI Match Script

    Posted May 03, 2021 06:08 AM
    Hii Geetha,

    This means your if condition is not getting fulfilled and hence that part of script is not getting executed. If the script is executed then you should be able to see the values instead of variable in response.

    If your file name format is "transref_guid_Geetha_123" and you want to store some value out of it you can use substring function (i assume the length will remain same)

    Hope this helps.

    Thanks


    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 9.  RE: Reuse of a variable in VSI Match Script

    Posted May 04, 2021 01:53 AM
    Hi Geetha,

    Simplest reason why you are unable to see the value resonated in the response might be due to, the setStateValue not executed inside the if loop.

    Try the below logic

    -> fetch the transref & guid (I assume both are 2 different arguments in the incoming req)
    -> Loop through your list of file names
    -> find if any file name that "contains" transref & guid
    -> pick the length of the filename, and find the substring of the last digits (if you know the length)
    -> pick the length of the filename, and exclude the substring of transref & guid and pick only the remaining last digits (if you do not know the length)
    -> setStateValue to a variable and you should be able to use it in the response.

    Not sure why you are trying this inside match scripts (unless you have to choose response based on certain conditions). This could you be moved to Scriptable DPH for better maintainability.

    Thanks
    Senthil Manohar