Parsing AR System table entries
An AR System table field can contain many selectable results. You should parse each row entry so that later you can randomly select a row (see Using-random-variables). You can parse a table programmatically.
A GetTableEntryList call returns table entries. In Silk TrueLog Explorer, the response to the call looks similar to the follow excerpt:
this.result={f:[{t:"Char",dt:4},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Time",
dt:7},{t:"Time",dt:7},{t:"Char",dt:4},{t:"Enum",dt:6,et:0,e:{1000:"Draft",1500:"In Review",
2000:"Pending",3000:"Waiting Approval",4000:"Planning",5000:"In Progress",6000:"Completed",
7000:"Rejected",8000:"Canceled",9000:"Closed"}},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Char",
dt:4},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Char",dt:4},{t:"Enum",dt:6,et:0,
e:{1000:"1-Critical",2000:"2-High",3000:"3-Medium",4000:"4-Low"}}],r:[{i:"000000000009040",
d:[{v:"<img src=../../../../apps/myServerName/Remedy%20Service%20Request%20and%20Catalog%
20System/resources/InProgress.gif alt=\"In Progress\" title=\"In Progress\">",p:"<img src=
../../../../apps/myServerName/Remedy%20Service%20Request%20and%20Catalog%20System/resources/
InProgress.gif alt=\"In Progress\" title=\"In Progress\">"},{v:"REQ000000009039",
p:"REQ000000009039"},{v:"SRDtest-1007",p:"SRDtest-1007"},{v:"In Progress",p:"In Progress"},
{v:"4/10/2007 8:02:08 AM",p:"1176217328"},{v:"4/10/2007",p:"1176217325"},{v:"<a href=../../
SRS:RequestDetails/?mode=display&F1000000829=REQ000000009039&F302832400=
LaunchedViaURL&F303003600=1 target=\" blank\">View Details</a>",p:"<a href=../../
SRS:RequestDetails/?mode=display&F1000000829=REQ000000009039&F302832400=
LaunchedViaURL&F303003600=1 target=\"_blank\">View Details</a>"},{v:"In Progress",p:"5000"},
{v:"Planning In Progress",p:"Planning In Progress"},{v:"",t:0,p:""},{v:"000000000009040",
p:"000000000009040"},{v:"SR00142215278B7qYbRgI1YJAAUKcA",p:"SR00142215278B7qYbRgI1YJAAUKcA"},
{v:"SR00142215278Bn88aRgpfylFAr1MD",p:"SR00142215278Bn88aRgpfylFAr1MD"},{v:"",t:0,p:""},
{v:"",t:0,p:""},{v:"3-Medium",p:"3000"}],rc:-1},
............
,idmap:{"000000000009040":0,"000000000009035":1,"000000000009020":2,"000000000009013":3,
"000000000009012":4,"000000000009011":5,"000000000009010":6,"000000000009009":7,
"000000000009008":8,"000000000009007":9,"000000000009006":10,"000000000009005":11,
"000000000009004":12,"000000000009003":13,"000000000009002":14,
"000000000009001":15,"000000000008011":16,"000000000008008":17,"000000000008007":18,
"000000000008005":19,"000000000008004":20,"000000000008003":21,"000000000008002":22,
"000000000008001":23},q:"{qual:\"1\\\\2\\\\4\\\\1\\\\1\\\\1000000338\\\\2\\\\4\\\\10\\\\
12200-Test\\\\4\\\\1\\\\1\\\\1000000337\\\\2\\\\4\\\\10\\\\12200-Test\\\\4\\\\4\\\\1\\\\7
\\\\2\\\\2\\\\6000\\\\\"}",n:24,start:0};
In SilkPerformer, the following functions are the most useful for parsing a string or response:
- StrSearchDelimited() - Parses strings
- WebParseDataBound() - Parses HTTP responses
- WebParseDataBoundEx() - Parses HTTP responses
The GetTableEntryList response can be parsed for all 24 entries (n:24 at the end of the string indicates the response contains 24 entries). To parse the response for the specified number of entries programmatically, use the StrSearchDelimited function. This function searches for beginning and ending delimiters and saves everything in between to a variable.
To parse for entries, look for beginning and ending strings that separate one entry from another. In this case, the string r:[{i: begins the entry, and }],rc:-1} ends the entry. Using StrSearchDelimited, do this in a for loop through all 24 entries, and save each entry into an array.
Then, loop 24 times through the array of entries, and parse again for the values you are interested in. These values are usually the entry ID, names, and instance IDs.
Following is the code used to parse for entries:
function parseRequestList(inStr : string(900000))
var
strNum, strTemp : string;
i, j, loopMax, counter : number;
aInfo : array[MAX INT] of string(40000);
begin
// Find number of returned elements
StrSearchDelimited(strNum,STRING COMPLETE,inStr,"n:",1,",",1,STR SEARCH FIRST);
gnTotalRequests := number(strNum);
// Break up into a set.
j := 1;
StrSearchDelimited(aInfo[j],STRING COMPLETE,inStr,"{i:",1,"],rc:}",1,STR SEARCH FIRST);
for j := 2 to (gnTotalRequests) do
StrSearchDelimited(aInfo[j],STRING COMPLETE,inStr,"{i:",1,"],rc:}",1,
STR SEARCH NEXT);
end;
// Now loop through each element in aInfo and parse for the values.
for i := 1 to gnTotalRequests do
StrSearchDelimited(gaRequestID[i],STRING COMPLETE,aInfo[i],
"{v:\"",2,"\"",1,STR SEARCH FIRST);
StrSearchDelimited(gaRequestInstanceID01[i],STRING_COMPLETE,aInfo[i],
"{v:\"",10,"\"",1,STR SEARCH NEXT);
StrSearchDelimited(gaRequestInstanceID02[i],STRING_COMPLETE,aInfo[i],
"{v:\"",1,"\"",1,STR SEARCH NEXT);
end;
end parseRequestList;