0

i want to get defect id from the url using groovy code (To build custom code in tasktop).

for example: I will have an dynamic url generated say www.xyz.com/abc/defect_123/ now I want to retrieve that letter that always starts from 17th position. and return the string

Please help.. Thanks in advance

tim_yates
  • 167,322
  • 27
  • 342
  • 338

2 Answers2

0

Here are two possibilities. Please note that the "substring" option is very strict and will always start from the 16th position (what happens if the domain changes from www.xyz.com to www.xyzw.com?)

def str = 'www.xyz.com/abc/defect_123/';

def pieces = str.tokenize('/'); // prints defect_123
def from16 = str.substring(16); // prints defect_123/

println from16;
println pieces.last();
Danilo
  • 2,676
  • 7
  • 32
  • 36
0

You should define this as dynamic url in UrlMappings.groovy file:

"www.xyz.com/abc/$defect_id" (controller: 'YourController', action: 'method_name')

and you can access the defect_id variable from YourController using params.defect_id

UditS
  • 1,936
  • 17
  • 37