@pkn3081 You're hitting all the roadblocks I encountered. I was returning an array in my function and it was showing as "Object". The fix is to return a string. It's possible to parse the returned "Object" if you feed it to some action that takes that type of object as imput (possibly a datatable). But with the lack of documentation on many of these actions in power automate, you'd have to resort to trial and error and it's still not guaranteed you'd make it work.
I discovered that my issue is I was using Chrome instead of Edge (apparently the MSFT team skipped Chrome testing before rolling out this feature. LOL). Now my function is at least returning what I expect it. But the javascript action is oddly executing sometimes and not others. I noticed that I have to go into the developer tools to get the javascript action to execute the first time. After that it seems to return the expected result on subsequent executions. I don't think I can rely on this workaround in production for an enterprise solution. Anyone else know how to fix this intermittent javascript execution problem?
I haven't dealt with pagination yet. But it sounds like you need to work with dynamic selectors instead of looking for IDs or text that change. Here's a scenario I ran into that you might find helpful.
I had to loop through rows of data (product lines) where I needed to get access to all the input fields (textboxes and checkboxes) on each row. The input IDs are all dynamic. So I initially added one of the UI Elements using the "Add UI Element" method. Once the element is created, I renamed the element as "DynamicID input Text" and edited the selector to reference a variable such as: input[Id="%dynamicFieldID%"]
(Note that your selector could be completely different. you can use any css selector that would return your field. I'd suggest you first test your selector in the developer console until you get the correct result before moving on to add the UI element)
Then in my flow, I have a for-each loop that loops through each row. I have one "Get Details of element on a webpage" action and I set its property to get "Own Text" and the UI element set to the "DynamicID input Text" element (see the screenshot).
I hope you can glean some information to solve your problem. If you do, please post back your solution.
Good luck!
WE NEED POWER AUTOMATE TO BE ENTERPRISE GRADE BADLY! COME ON MICROSOFT!
p.s. Here's my javascript function I used to find the text fields. hope someone finds it useful.
function ExecuteScript() {
const data = [];
var rows = document.querySelectorAll("tr[_awtisprimaryrow][bgcolor]");
for (var i=0; i<rows.length; i++) {
var elems = rows[i].getElementsByTagName("input");
var line="";
for (var j=0; j<elems.length; j++) {
var singleElem = elems[j];
/*This is for debugging purposes*/
/*if (singleElem.id == "_iq49kd"){
singleElem.value = "1234567";
} */
if (j < elems.length - 1) {
line += singleElem.id + "~" + singleElem.value + "|";
} else {
line += singleElem.id + "~" + singleElem.value;
}
}
if (line.length > 0){
data.push(line);
}
line = "";
}
/* You can return anything you'd like here */
/*return data; */
/*return "This is a test in Edge Browser"; */
return data.toString().replace("[", "").replace("]", "").replace('"', '');
}