Highlighted
New Member.
10467 views

lr_paramarr_random - which id was used

Jump to solution

 

how to get ID of used random dataset.? We populate array with follwoing function:

web_reg_save_param_ex("ParamName=parray", "LB=\myBoundary\":","RB=,\"","Ordinal=ALL",LAST);
This provides data like designed:

parray_1 = 1000
parray_2 = 1230
...
parray_10 = 1022
parray_count = 10

In order to proceed next steps in script we use function lr_paramarr_random in order to populate variable "pToBeUsedInScript" with this

do {
            lr_save_string(lr_paramarr_random("parray"),"pToBeUsedInScript");             
        } while (atoi(strstr(lr_eval_string( "{pToBeUsedInScript}" ),"1300")) ==1230);

This will filter data that is outdated for our process.

Unfortunately next step needs number of row as integer for posting data. We want to use atoi(<used_array_id>) but how to get this ?

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

Re: lr_paramarr_random - which id was used

Jump to solution

OK so before I found out about lr_paramarr (or before it was introduced into LR!), I used to randomly select values by writing code, here's an example:

//Declare these 3 variables in your script or in globals.h
int iMax;
charBufferRow[50];
char cTempBuf[50];

//Declare random function at the top your script
srand(time(NULL));

//Capture the dynamic value
web_reg_save_param_ex("ParamName=parray",  "LB=\myBoundary\":""RB=,\"" ,"Ordinal=ALL"LAST);

//Step goes here

//1 - iMax stores the count of captures
iMax = atoi(lr_eval_string("{parray_count}") );

//2 - Here we take the count, select a random one and save it into cTempBuf
sprintf(BufferRow, "%d", rand() % iMax + 1);

//3 - Here we output the row used - this is the bit you're after
lr_output_message(BufferRow);

//4 - Here we repeat selecting the random value from the count but this time add it to the captured value
sprintf(cTempBuf, "{parray_%d}", rand() % iMax + 1);

//5 - Here we finally save out the randomly selected dynamic value into the new parameter called 'Selected_Parray'
lr_save_string(lr_eval_string(cTempBuf), "Selected_Parray");

So whilst this is a long winded way of doing things (you could get rid steps 2 and 3 if you didn't need to see the selected row), you can see the row is saved into the char 'BufferRow'.
If you need to save this into a string which can be later used in the script then just use the lr_save_string function afterwards.

View solution in original post

0 Likes
5 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: lr_paramarr_random - which id was used

Jump to solution

Hi

There is no way to know which index that was used.

But solving our need is only to do it the other way around. You create a random number yourself between 1 and parray_count and then use lr_paramarr_idx() instead.

lr_save_string(lr_paramarr_idx("parray", rnd_index),"pToBeUsedInScript");

 
br /ola


Please mark post as solved if your problems or questions is/are resolved.
If this post was valuable to you, please consider kudo it.

.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: lr_paramarr_random - which id was used

Jump to solution

Not sure I fully understand the question, are you asking how to display which ordinal value was used? Surely you could just print the value of 'parray_count' ?

0 Likes
Highlighted
New Member.

Re: lr_paramarr_random - which id was used

Jump to solution

we tried to get index number e.g. parray_2 ==> "2"

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: lr_paramarr_random - which id was used

Jump to solution

OK so before I found out about lr_paramarr (or before it was introduced into LR!), I used to randomly select values by writing code, here's an example:

//Declare these 3 variables in your script or in globals.h
int iMax;
charBufferRow[50];
char cTempBuf[50];

//Declare random function at the top your script
srand(time(NULL));

//Capture the dynamic value
web_reg_save_param_ex("ParamName=parray",  "LB=\myBoundary\":""RB=,\"" ,"Ordinal=ALL"LAST);

//Step goes here

//1 - iMax stores the count of captures
iMax = atoi(lr_eval_string("{parray_count}") );

//2 - Here we take the count, select a random one and save it into cTempBuf
sprintf(BufferRow, "%d", rand() % iMax + 1);

//3 - Here we output the row used - this is the bit you're after
lr_output_message(BufferRow);

//4 - Here we repeat selecting the random value from the count but this time add it to the captured value
sprintf(cTempBuf, "{parray_%d}", rand() % iMax + 1);

//5 - Here we finally save out the randomly selected dynamic value into the new parameter called 'Selected_Parray'
lr_save_string(lr_eval_string(cTempBuf), "Selected_Parray");

So whilst this is a long winded way of doing things (you could get rid steps 2 and 3 if you didn't need to see the selected row), you can see the row is saved into the char 'BufferRow'.
If you need to save this into a string which can be later used in the script then just use the lr_save_string function afterwards.

View solution in original post

0 Likes
Highlighted
New Member.

Re: lr_paramarr_random - which id was used

Jump to solution

Thanks for strategy and provided sample code. I managed our requirement based on this input. 

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.