'SoapUI + Groovy + Fetch last ID value from response payload

In SoapUI response using Groovy, I am not able to fetch last ID value ie 125114.

http://199.xxx.10.20:8080/test_link/masters/125114

How can fetch that value?



Solution 1:[1]

You can split the url by '/' and get the last element. A possible groovy code to do this in SOAPUI:

def url = ('http://199.xxx.10.20:8080/test_link/masters/125114');
def strArray = url.split("/");
def fetchId = strArray.last();
log.info fetchId;

Hope this helps,

Solution 2:[2]

Use of tokenize, gives the result.

def url = ('http://199.xxx.10.20:8080/test_link/masters/125114');
def strArray = url.tokenize('/');
def fetchId = strArray.last();
log.info fetchId;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 albciff
Solution 2 Rubyist