Number of elements in the array - web-services

Here is the logic I used in the while loop, the value of i is 1 $i<=ora:countNodes(bpws:getVariableData('inputVariable','payload','/ns1:Input/ns1:Add')).
Here is the xsd I created for reference
<xsd:element name="Add" type="xsd:int" maxOccurs="unbounded"/>
When I used countNodes it's throwing an error. Can anyone please explain me where am I going wrong and what function should I use to find total number of elements in the array.Thanks in advance.

If you are doing it in the BPEL process. Please do it step by step as follow:
Use Assign Component for initialize Increment, NodeCount Variables.
a.Increment Variable initialize it to '1'
b.Find out the node count of the Array variable using
ora:countNodes('InputVariable','Payload','element')
Use the While-Loop Component with condition Increment Variable< NodeCount Variable
At the end of the Loop increment the Increment Variable by '1'
Let me know if you need any thing else..

$i<=ora:countNodes(bpws:getVariableData('inputVariable','payload','/ns1:Input/ns1:Add'))
here instead of countNodes, using count works.Thanks.

Related

Turning an Xpath into a list variable and use For loop

I'm very new to robot framework. This question is about creating a list variable using Xpath.
I'm trying to write a FOR LOOP in robot in order to print all items that appear on a search result page. Here is what I've done so far:
I tried to declare a list variable using Xpath:
#{product} //div[contains(#class,'ProductCard__TitleMaxLines')]
This Xpath has the number of repetitions the same as the number of items on the page, e.g. 20, so I assume that this list will contain 20 members. --> Is this how it works?
I created a For loop:
${index} Set variable 1
For ${product} in #{related_product}
Exit for loop if ${index} > 20
Log to console ${product}
${index} Evaluate ${index}+1
End
For this, I assume that it will take the first product found on the Xpath to be index=1, and the next index=2, and so on.
That's all I've done so far. Please advise if this works correctly or if there is another way that is better and more typical.
I think your question is, you have similar kind of xpath around 20 times in the webpage. If my understanding is correct, you should use the Get Webelements keyword from Selenium Library.
#{product} Get Webelements //div[contains(#class,'ProductCard__TitleMaxLines')]
The above line will create the list of webelements which having the same xpath

Is there any way to get value from specified position From List variable Automation Anywhere?

I want to get a value from particular location from list variable. Right now what i see is it only uses loop to iterate over in Automation anywhere.
SO is there any way to get value from a specified location?
For now, this is your only option to get a value from a specific location/index on a list.
I hope that Automation Anywhere includes a command/option to do that in the next release(s).
Unfortunately you'll have to loop over the list, and have a counter variable to get the item on the position you want.
After that you exit the loop. Not very efficient, but I just had to do it today :(
You can directly access the list elements, you can modify and delete them directly much easier and quicker in G1ANT software, even without executing the loop.
Here is the sample code:
♥list = Adam❚Eva❚John❚Mary
♥list⟦1⟧ = Peter
dialog ♥list
♥list⟦⟧ = 200
♥list⟦5⟧ = ♥list⟦5⟧+10
dialog ♥list
Enjoy!

Is there a way to access the iteration number in Postman REST Client?

I'm using postman for API testing. I'm running a large number of tests and I want to print the iteration number to the console on some of them. Is there a way to get the iteration number as an environment-like variable?
According to Postman API Reference, pm.info.iteration - is the value of the current iteration being run.
Example:
console.log(pm.info.iteration);
It is possible now! You can access the iteration variable, in the same way you access other variables like responseBody.
I don't know if there is an internal way to get the iteration number but I believe you should be able to track this number through code yourself. Here's a quick code snippet:
var value = environment.count;
value++;
postman.setEnvironmentVariable("count", value);
If you put this in the pre-request editor or the test editor of a collection that you are sure will run once per iteration it will effectively track the iteration count.
You can get the iteration number with
pm.info.iteration:Number
Is the value of the current iteration being run.
Postman Sandbox API reference
I got there like this:
const count = pm.info.iteration+1
console.log("======== LITERATION "+count+" ========");

Circular Double Linked list visualization using natvis

I would like to write a natvis visualizer for a double linked list. The list does not have a count node stored, and the easy way does not work very well, as the expansion never stops (next is never null, the last item of the list is pointing to the list root).
<Type Name="TListBidir<*>">
<Expand>
<LinkedListItems>
<HeadPointer>next</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>($T1 *)this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
I hoped I will be able to add a Condition attribute the the NextPointer comparing it with the list head, but as the NextPoint is evaluated in the context of the node, I do not know what to compare it with:
<NextPointer Condition="next!=XXXXXXXXX">next</NextPointer>
This is how it looked like with previous (2010) visualizers, using the skip directive, as the #list was handling this automatically:
#list is protected against infinite traversals and will cope gracefully with a circular list. Also, you can use a skip: expression to denote a sentinel node that should not be reported. Although the name implies that the node will be skipped, it actually causes traversal to stop, so if your sentinel node is first you should start traversal after it.
TListBidir<*,*,*>{
children
(
#list(
head: ((($T2 *)&$c)->next),
next: next,
skip : &($c)
): (($T1 *)(&$e))
)
}
How can I explain in the natvis to the debugger it should stop expanding the list once it reaches the root element again?
I had a similar problem, not with a circular list, but with a sentinel node at the end that pointed at itself, and came up with an interesting solution that might be adaptable to your needs: You could use the ternary operator to fake out a real termination. The expressions inside <NextPointer> can be anything you can write in vanilla C, so you can do real computation in there (but sadly, no recursion).
(Note that you're not allowed to put a Condition attribute on <NextPointer>, so the ternary operator is the only way to accomplish conditions there.)
So in my case, the list terminated like this:
<LinkedListItems>
<HeadPointer>this</HeadPointer>
<NextPointer>next != this ? next : 0</NextPointer>
<ValueNode>items</ValueNode>
</LinkedListItems>
In your case, if the nodes each have a pointer to their container, you can use that to compare against the head node:
<LinkedListItems>
<HeadPointer>container->head</HeadPointer>
<NextPointer>next != container->head ? next : 0</NextPointer>
<ValueNode>items</ValueNode>
</LinkedListItems>
Or, without the > entities and written as more traditional C, that's equivalent to:
next != container->head ? next : NULL
If you don't have some kind of container back-pointer, though, you're probably out of luck on this, since there's no way by looking at only a single node in a circularly-linked list to answer whether it's effectively the "last" node.
You can do this with a CustomListItems element:
<CustomListItems>
<Variable Name="orig_head" InitialValue="head"/>
<Variable Name="iter" InitialValue="first_elem"/>
<Loop>
<Break Condition="iter == orig_head || iter == 0"/>
<Item>*iter</Item>
<Exec>iter = iter->next_elem</Exec>
</Loop>
</CustomListItems>
CustomListItems allows you to save the head in a variable so it can be used while traversing the list. If your head has a different type then the list nodes you will need to cast it to the node type.
The natvis framework does not currently support circular linked lists without a count provided. If you provide a count, it should work. However, without a count, there is no good way to prevent the expansion from just continuing on forever.

Getting values from CFLOOP

I am trying to pull out values from a CFLOOP and dump them but I seem to be missing something.I need to extract openHours from the first loop and openMinutes from the second and put them in variables that will then run a query for submitting the values in the database.
This is my struct when I dump out #form#. I need to get the variable form.openHours1 the problem is that openHours gets its number by #CountVar# so basically i need to dump out something like #form.openHours[CountVar]#
struct
FIELDNAMES POSTITNOW,OPENHOURS1,OPENHOURS2,OPENHOURS3,OPENHOURS4,OPENHOURS5,OPENHOURS6,OPENHOURS7
OPENHOURS1 13
OPENHOURS2 13
OPENHOURS3 12
OPENHOURS4 0
OPENHOURS5 0
OPENHOURS6 0
OPENHOURS7 0
POSTITNOW YES
Rather than #form.openHours[CountVar]# what you want is:
form["openHours" & CountVar]
As a scope, FORM is also a struct and you can use array notation to get at the values.
This is key for working with dynamic form field names.
To clarify:
form.openHours7
is equivalent to
form["openHours7"]
The first is generally known as dot-notation, the second as array-notation (since it resembles how you refer to array elements.
Since the value in the bracket is a string, you can replace it with a variable.
<cfset fieldToUse = "openHours7">
<cfoutput>#form[fieldToUse]#</cfoutput>
Or, as I opened with, a combination of a literal string and a variable.
You can't really do that with dot-notation. (At least not without using evaluate(), which is generally not recommended.)
The documentation has lots of information on how to work with structures, including the different notation methods.
I think you want this, or something very similar:
<cfoutput>
<cfloop from="1" to="7" index="CountVar">
#openHours[CountVar]#<br>
</cfloop>
</cfoutput>
Sorry, this is a little murky to me, but that's never stopped me from jumping in. Are you going to have an equal number of openhours and openminutes? Can you just loop over form.fieldnames? As it stands now, you have fields named openhours1-N, it sounds like openminutes1-N is yet to be added. It seems that you could loop over fieldnames, if the field starts with openhours you get the number off the end and then you can easily create the corresponding openminutes field. As Al said (much) earlier, you would then most likely use array-notation to get the values out of the form structure.
Another thought is that form field names don't have to be unique. If you had multiple occurrences of "openhours", ColdFusion would turn that into a list for you, then you could just loop over that list.