## Print from History using math

Discuss your general Proclaim related queries here.
lzhu19
Posts: 3
Joined: Mon Jun 10, 2019 6:39 pm
Has thanked: 1 time

### Print from History using math

Hi all,

I am quite new to Proclaim and there is a function I want to build but I can't seem to find related documents on doing this.
I have pulled a selected list of History File into a table and I need to print them in order.

Also, it doesn't seems like I can get access to the file just by using print with the document_code I get from file:

I tried to get the file by:
v = FETCH( "CONTENT" , "History" , "document_code" , "FOR FIRST History NO-LOCK WHERE History.case_no = '" + {case.key} + "' AND (document_code = '" v-result "' )" )

that will only return me the code, which I already have. How would I get the document itself?

HERE is what I have so far with some pseudo code
v-entries = TABLECOUNT( {TEST-FILES-FROM-FOLDER.Table} )
TABLEFIRST( {TEST-FILES-FROM-FOLDER.Table} )
v-result = {TEST-FFF-FileNo.Text}
v = FETCH( "CONTENT" , "History" , "document_code" , "FOR FIRST History NO-LOCK WHERE History.case_no = '" + {case.key} + "' AND (document_code = '" v-result "' )" )
#PRINT( v )
### go to history and find the entry that matches with the file number
### add them to a list if list is even a thing
#WHILE v-entries > 0 DO
# TABLENEXT( {TEST-FILES-FROM-FOLDER.Table} )
# v-result = {TEST-FFF-FileNo.Text}
# v-entries = v-entries -1
# print the file selected
#END

steve
Posts: 408
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 91 times

### Re: Print from History using math

Hi,
can you clarify your requirements a little - as I understand it:

you've created a proclaim Table containing a list of a handful of history rows - specifically your table contains the document_code of the history documents/files (word/pdf etc)that you want to print? - eg something like

Date // Description // Document_code
01/01/2019 // test doc 1 // 12345678
02/02/2019 // test doc 2 // 12345679

is this correct?

Then you want to be able to print out each document in that table, by e.g. pressing a button on a screen?

v = FETCH( "CONTENT" , "History" , "document_code" , "FOR FIRST History NO-LOCK WHERE History.case_no = '" + {case.key} + "' AND (document_code = '" v-result "' )" )
will just return the very same document code (e.g. 12345678) that you have defined in the variable v-result. Your new variable "v" will just contain the number "12345678". If nothing else, this line of code will sanity check that the document code in 'v-result' is valid.

Likewise the "PRINT" command in Proclaim Maths is very primitive and probably won't do what you think/hope it does (namely print a file/document!)

Let us know if my interpretation of your requirements is on the right track, then we'll hopefully be able to point you in the right direction.

lzhu19
Posts: 3
Joined: Mon Jun 10, 2019 6:39 pm
Has thanked: 1 time

### Re: Print from History using math

Hi Steve,

You are correct in your interpretation. I need to print off all the files in the table in the order it is set, based on the folder they are in (this is already done).
The execution would be carried out through a button, which iterate through each row in table and print the corresponding file.

Initially I was trying to create a PDF bundle of the items in the table, but I could not find a good way to push an array into the MEMO for creating a PDF Bundle. Do you have any insight in doing this?

Thanks,

steve
Posts: 408
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 91 times

### Re: Print from History using math

Hi,
can you try something out for me, and see if this is a valid approach for you:
make a test Word or PDF file, and store it somewhere on your computer like c:\temp\test.doc
make a linked action with the following maths:

Code: Select all

COPY-FILE ("c:\temp\test.doc", "\\path\\to\\your\\network\\printer")
(obviously replacing the second argument with your actual printer path\name)

if it works, and is a suitable direct print method for you, then we can elaborate on how to extend it to print to any file in a table

failing that, your last resort might be making, e.g. 30 embedded doc holding fields, attach these to a memo bundle, then looping through your table and PUTting each history document's code into its own holding field, then producing the bundle.

lzhu19
Posts: 3
Joined: Mon Jun 10, 2019 6:39 pm
Has thanked: 1 time

### Re: Print from History using math

Hi Steve,

Copy file to printer does the job nicely. I guess the next step is to find where the file resides for history file? For our case, it might be more beneficial if we do binders, as print jobs tends to get mixed up a lot. So when you say:
looping through your table and PUTting each history document's code into its own holding field
So I assume with this, the embedded document can find the actual file just based on the document code?

steve
Posts: 408
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 91 times

### Re: Print from History using math

Yes that's right - you can find the absolute file path given the document code, but it's a bit messy.

The history document will be stored in any of up to 4 'document archive' locations as defined in User Profiles for the Default User/"Main" tab.
Archive/Extra Archive 1/2/3.

Within the archive, each file is stored in a subdirectory matching the first 6 digits:
For example, if you have the document_code "12345678", which is a .PDF file, and a document archive of \\server\prodisk\archive
the absolute path to this file is:
\\server\prodisk\archive\12\34\56\12345678.PDF

So, given the document_code, we can reconstruct the full file path if we also know

* the file extension and
* the archive location

We can retrieve these from the database using FETCH, and combine it into a Maths field to re-use it. You would loop through your table, pass the document_code to this maths via e.g.a Global Variable or a holding field, then use the RESULT of the maths to print out the file.
Here's some pseudocode:

Code: Select all

# Maths field whose RESULT is the full file path for a given document_code
# what is our document code? let's hard-code a demo value, but perhaps use a Global Variable instead
#
vdoc ="12345678"
#
#=====
# what file extension is it: vext
# This is stored as e.g. "WORD-DOC" ,  "ADOBE-PDF" etc
# so we need to reformat it
#=====
vext = FETCH( "CONTENT" , "History" , "document_format" , "FOR LAST History NO-LOCK WHERE (document_code = '" + vdoc + "' )" )
#..find the hyphen
vfind = "-"
vlocation = 0
vlen = LENGTH( vext )
i = 1
WHILE i <= vlen DO
vchar = SPLIT( vext , i , 1 )
IF vchar = vfind THEN
vlocation = i
i = vlen
END
i = i +1
END
#...vlocation now points to the hyphen.
vextlen = vlen - vlocation
vlocation = vlocation + 1
#...split to get the file extension
vext = SPLIT( vext , vlocation , vextlen )
#
#=====
#what subdirectory will this be in? : vsub
# e.g. for 12345678 the subdirectory tree will be 12\34\56
#=====
vsub1 = SPLIT( vdoc , 1 , 2 )
vsub2 = SPLIT( vdoc , 3 , 2 )
vsub3 = SPLIT( vdoc , 5 , 2 )
vsub = TEXT( vsub1 ) + "\" + TEXT( vsub2 ) + "\" + TEXT( vsub3 )
#=====
# create 4 possible file paths - the doc is either in the archive, extraarchive1  extraarchive2 or extraarchive3
#=====
# Doc archive root directories:
vdir1 = FETCH( "CONTENT" , "user-params" , "docs-archive" , "FOR EACH user-params NO-LOCK WHERE users-id='DEFAULT'" )
vdir2 = FETCH( "CONTENT" , "user-params" , "extra-archive1" , "FOR EACH user-params NO-LOCK WHERE users-id='DEFAULT'" )
vdir3 = FETCH( "CONTENT" , "user-params" , "extra-archive2" , "FOR EACH user-params NO-LOCK WHERE users-id='DEFAULT'" )
vdir4 = FETCH( "CONTENT" , "user-params" , "extra-archive3" , "FOR EACH user-params NO-LOCK WHERE users-id='DEFAULT'" )
# What are the 4 possible full file paths for our given document_cde
vpath1 = TEXT( vdir1 ) + "\" + TEXT( vsub ) + "\" + TEXT( vdoc ) + "." + TEXT( vext )
vpath2 = TEXT( vdir2 ) + "\" + TEXT( vsub ) + "\" + TEXT( vdoc ) + "." + TEXT( vext )
vpath3 = TEXT( vdir3 ) + "\" + TEXT( vsub ) + "\" + TEXT( vdoc ) + "." + TEXT( vext )
vpath4 = TEXT( vdir4 ) + "\" + TEXT( vsub ) + "\" + TEXT( vdoc ) + "." + TEXT( vext )
# Which on is it? Check the size:
vsize1 = FILE-SIZE( vpath1 )
vsize2 = FILE-SIZE( vpath2 )
vsize3 = FILE-SIZE( vpath3 )
vsize4 = FILE-SIZE( vpath4 )
# set the RESULT of the maths to the right path:
IF vsize1 <> -1 THEN
result = vpath1
ELSEIF vsize2 <> -1 THEN
result = vpath2
ELSEIF vsize3 <> -1 THEN
result = vpath3
ELSEIF vsize4 <> -1 THEN
result = vpath4
ELSE
result = ""
END

Usual caveats about using undocumented FETCH commands - may not work as expected in all versions of Proclaim etc.

bazzerfee
Posts: 8
Joined: Thu Jul 07, 2016 9:02 am
Has thanked: 1 time

### Re: Print from History using math

lzhu19 wrote:
Mon Jun 17, 2019 5:26 pm
Hi Steve,

Copy file to the printer does the job nicely. I guess the next step is to find where the file resides for history file? For our case, it might be more beneficial if we do binders, as print jobs tend to get mixed up a lot. So when you say:
looping through your table and PUTting each history document's code into its own holding field
So I assume with this, the embedded document can find the actual file just based on the document code?
I have set this up as you discussed but It seems that when the file arrives at the network printer there is nothing to print. When I see it in the que it says the document is a "Remote Downlevel Document" when I release it to print nothing prints?

Any ideas? I am a bit stumped?

steve
Posts: 408
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 91 times

### Re: Print from History using math

Hmm, is it the history fetch part or the COPY-FILE part that fails?
Can you try this, with a known good Word document file in c:\temp\test.doc :

Code: Select all

COPY-FILE ("c:\temp\test.doc", "\\path\\to\\your\\network\\printer")

bazzerfee
Posts: 8
Joined: Thu Jul 07, 2016 9:02 am
Has thanked: 1 time

### Re: Print from History using math

Hi the file location and name is spot on, and the copy-file command seems to work well as I see the print job hit the Printer queue, unfortunately, the printer seems to clear the print job and no print is produced. No error messages are created and the printer seems to work correctly for normal print jobs sent from word or Adobe directly.

Any ideas would help me