Back to Blog

Programmatically Create A Unique Parameter Name

Lets say you need to grab a list of items or numbers from a web page, such as GUID’s. These are not dynamic numbers, but will be used in a script as parameters. Here is how I captured the data I wanted and created my own DAT file:

  1. Figure out the format you want the DAT file to be in. For me, this was a GUID, another GUID, and a user ID. I created a file and put the top line in with the headers GUID1, GUID2, LOGIN and saved it to my C: drive in the root folder. I already knew the login so I had already set this up a a parameter called pLogin. The other two items I had to capture on the fly. For each user the list was different. Each user had between two and 60 items in their list.
  2. Figure out what you need to capture using the web_reg_save_param. I assume you already know how to do this. You will use the ORD=ALL to capture all of the items in the list that match your capture criteria, so make sure you have your boundaries set up so it will catch them all.
  3. Create a loop that gets the value of each of the things gathered by the ORD=ALL and spit them out to a file.

here is the code:


// Declarations

int i, ord;
int *reviewer_log;
char logdata[256];
char buid[64];
char asid[64];
char *outbufftemp;
char *outbufftemp2;

//Steps that captures the two GUID's



//Page that displays the information I want

"Name=Command", "Value=Login", ENDITEM,
"Name=email", "Value={pLogin}", ENDITEM,
"Name=password", "Value=password", ENDITEM,
"Name=TargetURL", "Value=Login.asp", ENDITEM,

//Count how many things you grabbed and put a message in the log

lr_output_message("Number of thing captured was %d", ord);

// Set up a loop that will start at the first thing captured, spit out the value
// to the log, and continue counting until you reach the value of ord.

for (i=1; i<=ord; i++){
    sprintf(buid, "{pBUIDNumber_%d}", i);
    outbufftemp = lr_eval_string(buid);
    sprintf(asid, "{pAssessmentNum_%d}", i);
    outbufftemp2 = lr_eval_string(asid);
    reviewer_log = (int *) fopen("C:\\reviewer_log.txt", "a");
    sprintf(logdata,"%s, %s, %s", outbufftemp, outbufftemp2, lr_eval_string("{pLogin}"));
    fwrite(logdata, sizeof(logdata), 1, reviewer_log);

//Run the script so that you iterated in seqential order the amount of times
// needed to go through all the logins.

//End Code


It has been pointed out that the fwrite function won’t remove the trailing spaces and it may be easier to use the fprintf function. See this code:


char logdata[80];
long stream;
extern int memset (char *, int, int);

char * my_username = "lenny";
char * my_password = "squiggy";

if((stream = fopen("c:\\successful_namepairs.txt","a"))== NULL)
    lr_error_message ("Opening of file failed");
    lr_log_message ("Login successful for %s", my_password);
return 0;

//---------------end code------------------------

Paste that into the action file and you should have a new file created in your C:\ folder.

The line should be “lenny, squiggy” without the trailing spaces.

Back to Blog