In report function field, how to extract specific text from another text field

AM24
Giga Guru

Hello,

 

I am creating a report currently on a table. That table has a description field, pretty much a text field whose value look something like this:

 

Random text

Repository: repository name

Created by: John

 

 

Would I be able to extract just "repository name"? I want this for a report. I was wondering if we can extract that with a functional field in the report. Thank you.

3 REPLIES 3

Bert_c1
Kilo Patron

Hi,

 

I have no idea what a 'functional field' in a report is. However, script logic for your example is:

 

var desc = "Random text\nRepository: repository name\nCreated by: John"
gs.info(desc);

var repoStr = desc.substring(desc.indexOf('Repository: '));
var nl = repoStr.indexOf('\n');  // assuming the desired value is on a line by itself
var repo = repoStr.substring(12, nl);
gs.info('repo = ' + repo + '.');

i think, functional field referring the column create for reporting this "Repository:" values along with other table column, this functional field not a column in source table.

GauravA69983980
Giga Contributor

Absolutely, this can be done. If the repository name always appears after "Repository:" in the description field, you can extract it using a calculated/functional field with a substring function.

For example, let's take logic in SQL:

 

SUBSTRING(description,
 CHARINDEX('Repository:', description) + LEN('Repository:'),
 CHARINDEX('Created by:', description) -
 (CHARINDEX('Repository:', description) + LEN('Repository:')))