Retrieving PDF from XML - Transaction Point

Discussions concerning general integration topics.

Moderator: Phil Barton

Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: Retrieving PDF from XML - Transaction Point

Post by Shevy »

so you can investigate all that is available to you by looking at the key names
Where do I find a list of these 'key names'? I searches in the Documentation under "iPrintjobItems" but I dont see a list of them. Also how would I call it? The line of code I got from you does a cast. HOw do I know what type to cast each property value to?
thanks.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Retrieving PDF from XML - Transaction Point

Post by roteague »

Shevy wrote:
so you can investigate all that is available to you by looking at the key names
Where do I find a list of these 'key names'? I searches in the Documentation under "iPrintjobItems" but I dont see a list of them. Also how would I call it? The line of code I got from you does a cast. HOw do I know what type to cast each property value to?
thanks.
Set a breakpoint on the code and add a watch. You will be able to see in the watch window what the values are.
Robert
Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: Retrieving PDF from XML - Transaction Point

Post by Shevy »

I am now trying to retrieve the titlecompany lookupcode for the order I am in.
Here is the code I used

Code: Select all

            
Dim titleCompany As SoftPro.OrderTracking.Client.ITitleCompany = TryCast(printJob.Properties("CoreOrder"), SoftPro.OrderTracking.Client.ITitleCompany)
Dim titlCod As String = titleCompany.LookupCode
I get an error:
"object reference not set to an instance of an object". and it breaks out on line Dim titlCod As String = titleCompany.LookupCode the value of "titleCompany" is null.
What am I doing wrong?
Mark McKenna

Re: Retrieving PDF from XML - Transaction Point

Post by Mark McKenna »

The CoreOrder property exposes an internal type to which you have no access. It is our internal representation of an Order business object, thus the cast to ITitleCompany fails (safely) and returns you a null reference which is then being used on the next line, causing the exception. Instead, use the Order property which is exposed as an SoftPro.OrderTracking.Client.IOrder interface reference. That provides you with protected access to the underlying order through an API proxy object, like...

Code: Select all

Dim iOrder as SoftPro.OrderTracking.Client.IOrder = TryCast( printJob.Properties["Order"], SoftPro.OrderTracking.Client.IOrder )
Dim orderNumber as String = iOrder.Number
CoreOrder exists on the pipeline as part of the print job because we manipulate it ourselves as the pipeline progresses. Remember that we are consumers of our own pipeline, so there will be some information in those exposed interfaces, like CoreOrder, that are not available from outside our internal code.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Retrieving PDF from XML - Transaction Point

Post by roteague »

Shevy wrote:I am now trying to retrieve the titlecompany lookupcode for the order I am in.
Here is the code I used

Code: Select all

            
Dim titleCompany As SoftPro.OrderTracking.Client.ITitleCompany = TryCast(printJob.Properties("CoreOrder"), SoftPro.OrderTracking.Client.ITitleCompany)
Dim titlCod As String = titleCompany.LookupCode
I get an error:
"object reference not set to an instance of an object". and it breaks out on line Dim titlCod As String = titleCompany.LookupCode the value of "titleCompany" is null.
What am I doing wrong?
Also, if you are going to do a TryCast you need to use it correctly. The purpose of the TryCast is that it will return "nothing" if the cast fails. Therefore, you also need to check the return value to keep an exception from being thrown:

Code: Select all

Dim titleCompany As SoftPro.OrderTracking.Client.ITitleCompany = TryCast(printJob.Properties("CoreOrder"), SoftPro.OrderTracking.Client.ITitleCompany)
        If titleCompany IsNot Nothing Then
            Dim titlCod As String = titleCompany.LookupCode
        End If
Robert
Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: Retrieving PDF from XML - Transaction Point

Post by Shevy »

I tried a few things and it is not working. Maybe you can help me out with this.
here is my code

Code: Select all

   Dim order As SoftPro.OrderTracking.Client.IOrder = TryCast(printJob.Properties("Order"), SoftPro.OrderTracking.Client.IOrder)
            Dim titleCompany As SoftPro.OrderTracking.Client.ITitleCompany = TryCast(order.TitleCompany, SoftPro.OrderTracking.Client.ITitleCompany)
            Dim titlCod As String = titleCompany.LookupCode
keeps on being null.
Can anyone give me the code for this? All I want is the Titlecompany lookupcode on a specific print job.
Thanks.
Mark McKenna

Re: Retrieving PDF from XML - Transaction Point

Post by Mark McKenna »

You will want to look at the SDK Help to gain an understanding of the types exposed by our API object model. In this particular example, the IOrder.TitleCompany property is not of type ITitleCompany, rather, it is of generic collection type IBusinessObjectList<ITitleCompany>. So your TryCast is failing and correctly handing you back a null reference, which then causes the exception on the next line. You should cast it to the generic collection type instead, and then use the methods available from that interface reference (which is most of the common collection actions since the interface implements IList, IEnumerable, etc.) in order to extract the information you are looking for.
Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: Retrieving PDF from XML - Transaction Point

Post by Shevy »

I need to know how to define a specific document in the ReadyDoc tree. can i use the
"docreportname", like this

Code: Select all

 Dim desc As String = TryCast(item.Properties("DocReportName"), String)
I need to know if there can be multiple documents with the same Docreportname.
Thanks.
Mark McKenna

Re: Retrieving PDF from XML - Transaction Point

Post by Mark McKenna »

This partially depends on the collation that is occurring, but in general, two print job items could certainly share a name. For example, if you have 2 HUD objects in your order and try to print HUD Page 1, you'll get 2 print job items that have the same name (DocReportName) but different contexts (PrimaryContextId or PrimaryContextName). Our ReadyDocs operate such that a single one may be executed for any number of qualifying business objects (there's only one "Commitment Schedule A" document, but it may be executed many times within the same batch/job - once for each qualifying Commitment in your Order).

Therefore, a unique print job item is typically identified by not only the document being printed, but also by the business object for which it was generated.

However... there is a print job handler that executes early in the pipeline that collates print job items according to a number of factors, including the document, object context, group, etc. This handler is responsible for the grouped output you see in email attachments and such. It essentially combines original print job items into new print job items, and then tries to retain any properties that are common to all items that were combined.

Example:
You have 2 documents being printed. As they hit the pipeline, there are 2 independent print job items created, each of which has all the applicable metadata, such as DocReportName and PrimaryContextId. The collation handler then runs and, based on its rules and the characteristics of the documents being printed, those 2 print job items may get merged into one new one. At this point, we try and apply any metadata to the new print job item that was common to every print job item that it was built from. So if both documents had the same name, the resultant merged print job item would retain the name. Otherwise, the name would be either null or the key would not exist.
Shevy
Posts: 48
Joined: Tue Dec 23, 2008 12:21 pm

Re: Retrieving PDF from XML - Transaction Point

Post by Shevy »

Thank you for your response.
I think for my purposes I can use the "DocReportName" since all I need to know is what category this document will belong to so that if there are 2 with the same name they will both belong to the same category anyway.

Now I am running into another problem, I think it has something to do with what you wrote, but I am not exactly sure I understood it:
So if both documents had the same name, the resultant merged print job item would retain the name. Otherwise, the name would be either null or the key would not exist.
The OnHandleDispatched function I am running works fine when I save one document. However when I try to save more than one document the DocReportName is empty for both files. Would you be able to explain why this may be happening?
Here is my basic fucntion:

Code: Select all

Protected Overloads Overrides Function OnHandleDispatched(ByVal printJob As IPrintJob) As Boolean
          If TryCast(printJob.Properties(PrintJobProperty.Targets), List(Of String)).Contains([Enum].GetName(GetType(PrintJobTarget), PrintJobTarget.Publish)) Then
             'first get the firmfile and username
            Dim order As SoftPro.OrderTracking.Client.IOrder = TryCast(printJob.Properties("Order"), SoftPro.OrderTracking.Client.IOrder)
            Dim firmfile As String = order.Number
            Dim currentUser As String = order.CurrentUser.UserName
            'get the connection string
            Dim strConnect As String = My.Settings.ConnectionString
            strSQL = "Select PDFLoc from controlrecord"
            Dim oData As New clsData
            Dim pdfLoc As String = oData.GetDataReader(strConnect, strSQL, "PDFLoc")
           'rip through the individual items in the print job 
            For Each item As IPrintJobItem In printJob.Items
                Dim fi As FileInfo = TryCast(item.Properties("FileLocation"), FileInfo)
               ''''''''''''''''''This line of code is bringing up empty string when there are more t han one document'''''''''''''''''
                Dim desc As String = TryCast(item.Properties("DocReportName"), String)
                Dim fileName As String = DateTime.Now.Millisecond & fi.Name
                Dim numPages As Integer = GetNoOfPagesPDF(fi.FullName)
                File.Move(fi.FullName, pdfLoc & fileName)
            Next
            MsgBox("Your document(s) have been published to the web successfully.")
            Return True
        End If
        'allow the pipeline to continue
        Return False
    End Function
Post Reply