Service Virtualization

 View Only

 How to get substring from a request argument value?

James Reece's profile image
James Reece posted Jan 31, 2023 05:37 AM
Hi all,

I want to extract substring from a request argument. I used workstation to set the argument as magic string by selecting the check box of the required argument and clicking Regenerate magic string button, and followed the approach mentioned in this post, 
https://community.broadcom.com/enterprisesoftware/discussion/how-to-split-the-request-argument-value-in-response#bm36e44052-fb91-4286-85c0-c88033a203e2

This approach didn't work for me, so
I tried using match script for this:

String id = incomingRequest.getArguments().get("request_user_id");
testExec.setStateValue("MyId",id.substring(5));

Using {{MyId}} in the response, but this didn't work either.
Could anyone suggest what would be the correct approach for this?

Thanks in Advance.

Danny Saro's profile image
Broadcom Employee Danny Saro

Hi James,

The argument name in the request object most likely is not "request_user_id" but only "user_id", have a look in the signature of that specific transaction what the exact name of the argument is? When you mark an argument as magic string then the runtime will create and store a property by prefixing it with "request_".

With regards to the approach in the post that didn't work for you, can you post the snippet of beanshell that you added to the response in the .vsi? Just for us to understand why that wouldn't have worked. 

Vaibhav Jain's profile image
Vaibhav Jain

Hi James,

Please let us know in case the solution worked for you after removing request_.

If no, please share the script used in your VSM

Thanks

Premalatha Gadde's profile image
Broadcom Employee Premalatha Gadde

Hi James,

Please look at the knowledge article Configure partial request account id {{=request_accountID.substring(1,5);}} in VSI response body fails and this should help you.

Regards,

Prema