This is a better representation of what I'm trying to accomplish and what I've tried.

Whether I use my original calculation (single variable), the two variable version, or the custom function, I only get exactly as desired if I put an actual number for the Occurrence in the Position function. If I use 1 I get "firstpdf", if I use 2, I get "secondpdf". That works just fine. However, if I try to use the variable, $pdfnum or $$pdfnum, I get the first instance just fine in $$insert, the rest return a blank to $$insert, which I'm watching in Data Viewer.

In the script example below Line #16 (and disabled #17) are the lines of interest. Line #17 was my last sample of the calculation using separate variables for the start and end positions. Line #16 is using the custom function from NRGSoft, which I've named ExtractXML.


Here is a snippet of the XML source which is imported into the field: "BaseImportXML::RAW Text".
-------------------------
<POD>
        <Order>
                <Id>24517</Id>
                <ProcessedBy>CT</ProcessedBy>
                <Quantity>13</Quantity>
                <Spoilage>2</Spoilage>
                <TotalQuantity>15</TotalQuantity>
                <Type>TEST</Type>
                <IncludeInserts>True</IncludeInserts>
                <BindItems>
                        <PDF>firstpdf</PDF>
                        <PDF>secondpdf</PDF>
                        <Insert>first insert</Insert>
                        <Insert>second insert</Insert>
                        <Insert>third insert</Insert>
                        <Insert>fourth insert</Insert>
                        <Insert>fifth insert</Insert>
                </BindItems>
-----------------------         

Here is the relevant portion of the script:

------------------

1       •       Go to Layout [ “BaseImportXML” (BaseImportXML) ]
2 • Perform Find [ Specified Find Requests: Find Records; Criteria: BaseImportXML::InsertFlag: “0” ] [ Restore ]
3       •       Go to Record/Request/Page [ First ]
4       •       Loop
5       •       Set Variable [ $$orderid; Value:BaseImportXML::OrderID ]
6       •       Set Variable [ $$totalquantity; 
Value:BaseImportXML::TotalQuantity ]
7       •       Set Variable [ $$ordinal; Value:1 ]
8       •       Set Variable [ $pdfnum; Value:1 ]
9       •       Set Variable [ $pdfnum2; Value:1 ]
10      •       Set Variable [ $$insertnum; Value:1 ]
11      •       Set Variable [ $$date; Value:BaseImportXML::EntryDate ]
12      •       Set Variable [ $$pdfcnt; Value:BaseImportXML::PDFCnt ]
13      •       Set Variable [ $$insertcnt; Value:BaseImportXML::InsertCnt ]
14      •       #Get PDFs
15      •       Loop
16 • Set Variable [ $$insert; Value:ExtractXML ( BaseImportXML::RAW Text ; "PDF" ; 1 ) ] 17 • // Set Variable [ $$insert; Value:Middle ( BaseImportXML::RAW Text ; Position (BaseImportXML::RAW Text;"<PDF>";1;$pdfnum)+5; Position (BaseImportXML::RAW Text;"</PDF>";1;$pdfnum2)-Position (BaseImportXML::RAW Text;"<PDF>";1;$pdfnum)-5) ]
18      •       Go to Layout [ “Inserts” (Inserts) ]
19      •       New Record/Request
20      •       Set Field [ Inserts::OrderID; $$orderid ]
21      •       Set Field [ Inserts::Insert; $$insert ]
22      •       Set Field [ Inserts::Ordinal; $$ordinal ]
23      •       Set Field [ Inserts::Type; "PDF" ]
24      •       Set Field [ Inserts::DateStamp; $$date ]
25      •       Set Field [ Inserts::PageCount; 4 ]
26      •       Set Variable [ $pdfnum; Value:$pdfnum+1 ]
27      •       Set Variable [ $pdfnum2; Value:$pdfnum2+1 ]
28      •       Set Variable [ $$ordinal; Value:$$ordinal+1 ]
29      •       Exit Loop If [ $$pdfnum>$$pdfcnt ]
30      •       End Loop        
---------------------





On Jun 6, 2008, at 12:21 PM, Ross Dickson wrote:

Andrew,

Your calculation will give the following results:
$num = 1
Position(Fieldname;"tag";1;1)+3 = 4
Position(Fieldname;"tag2";1;1) = 8
Result = Middle(Fieldname;4;4) = WORD

$num = 2
Position(Fieldname;"tag";1;2)+3 = 11
Position(Fieldname;"tag2";1;2) = 21
Result = Middle(Fieldname;11;10) = ¶tagWORD2t

$num = 3
Position(Fieldname;"tag";1;3)+3 = 16
Position(Fieldname;"tag2";1;3) = 34
Result = Middle(Fieldname;13;18) = WORD2tag2¶tagWORD3

Clearly not what you expected.

I would break each Set Field [WORD, WORD2, WORD3] script step into two, one to isolate the line containing the word and the surrounding tags, and the second to isolate the word. Once they are working you can merge them together, if you wish.

So (FN==Fieldname),

WORD = Middle("¶"&FN&"¶";Position(FN;"¶";1;$num)+1;
         Position(FN;"¶";1;1+$num)- Position(FN;"¶";1;$num)-1)
WORD = Middle(WORD; 4;Position(WORD;"tag2";1;1)-4)

Ross

Reply via email to