Super Contributor.. wdomerac Super Contributor..
Super Contributor..
598 views

How to get "line number" from HTML Code

Hi.

I'm using "Http Client Detailed Return" to get html code.

I need to find some string in this code and get it's line number.

For example in code:

(1.) <tr>
(2.) <th width="350"><span class="styl4">Flow name</span></th>
(3.) <th width="99"><span class="styl4">Time: Last Run</span></th>
(4.) <th width="50"><span class="styl4">State</span></th>
(5.) <th width="99"><span class="styl4">Time: Last Run</span></th>


I'm searching for string :"State" and results it's line number: "4"

Do you have idea ? There are filters in results of a operation. But it's getting string by line number. I need it inversely

Thanks for any suggestions. I need it to be the simplest...

Best Regards
WD

Labels (1)
0 Likes
5 Replies
GeorgeDK Absent Member.
Absent Member.

Re: How to get "line number" from HTML Code

Hello Wojciech,

 

I think the way forward is a scriptlet filter.

 

Unfortunately I cannot help with coding sucha filter but I think that this is the only filter with the capability to do what you need.

 

Kind regards,

 

George.

0 Likes
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to get "line number" from HTML Code

This scriptlet filter will return the line number of the text specified in the regular expression pattern (in this case "State", case sensitive).

 

It is splitting by newline so change that if needed; additionally the line numbers start at 0 so you can change that if needed as well.

 

var arrHtml;
var intLine;
var regPattern = new RegExp("State", "g");

try {
	arrHtml = scriptletInput.split("\n");
	for(var i = 0; i < arrHtml.length; i++) {
		if(regPattern.test(arrHtml[i])) {
			intLine = i;
			break;
		}
	}
	if(intLine != null) {
		scriptletResult = intLine; // <-- Fixed this line in edit
		scriptletResponse = "success";
	} else {
		scriptletResult = "Text not found";
		scriptletResponse = "failure";
	}
} catch(e) {
	scriptletResult = e;
	scriptletResponse = "failure";
}

 Hope this helps.

 

edit: Fixed scriptletResult assignment and for declaration (whoops shift key!)

0 Likes
Super Contributor.. wdomerac Super Contributor..
Super Contributor..

Re: How to get "line number" from HTML Code

Hi.

 

Thanks.

 

I have error:

 

ReferenceError: "I" is not defined.

 

How does it takes "input" from operation ? I would like to define input variable name. Is it possible ?

 

 

 

arrHtml = scriptletInput.split("\n");

 

How to "pass" a code to this scritplet.

 

I put this scriptlet in filters of a result. And input is a ${htmlCode} value.

 

Cheers

WD

0 Likes
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: How to get "line number" from HTML Code

Sorry, I made a small mistake in the scriptlet; unfortunately I didn't have access to OO at the time to test it.

 

I fixed the reference error in my original post; it should have been

scriptletResult = intLine //this
scriptletResult = i //not this

and also pressed the shift key on

for(var i = 0; i < arrHtml.length; i++) {

 

When using a scriptlet filter it takes input from whatever result field you have set this output to be from; for example it is coming from result field returnResult. You then access this input with

 

var input = scriptletInput;

 

If you use a scriptlet object as opposed to a filter you can handle inputs a lot better, however this does mean a seperate step to the object getting the result; I won't go into that here.

 

Since you are using the scriptlet as a filter to an existing result you don't really want to be calling many external variables. You should transform the result as much as you can with the in-built filters before using a scriptlet filter. For example, if the default output is not a newline either change the scriptlet to split on a different character or transform the result so it is on newlines.

 

However, if you want to access a flow variable external to the scriptlet you can use the call below (responded with the same thing in your other thread)

 

scriptletContext.getLocal("varName") // Get local OO var
scriptletContext.get("varName") // Get global OO var

 

Hope this makes sense.

0 Likes
Super Contributor.. wdomerac Super Contributor..
Super Contributor..

Re: How to get "line number" from HTML Code

Thanks 🙂

 

I was using scriptlets before. I was wondering only about for inputs according this script.

 

Best Regards
Wd

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.