Show pdf file after after linking

I am using an xml port where you can link a credit Safe report. But after the linking(that works) I alos want to showing the PDF file.

I have this:

ShowPDFCLient.ShowPDF(); is a table where the function ShowPDF(); is defined. The ShowPDF() function looks like this:


Setup.Read;

CALCFIELDS(PDF);
IF NOT PDF.HASVALUE THEN BEGIN
  TESTFIELD(PDF);
END;
PDF.CREATEINSTREAM(InStream);

Tools.ShowPDF(InStream);

But I get this error:

pdf.png

Thank you

But if I am using the button print pdf then it works.

This is the complete code:


 //Connect to CreditSafe:
Total := 0;
TotalFound := 0;
ReqCap := 0;
//total counter
Total := Total + 1;
ReqCap := ReqCap + 1;

//Create Request
Request.InitSearchRequest();

Request."Link Type" := Request."Link Type"::customer;
Request.VALIDATE("Link Code", "<Customer>"."No.");
{
IF (Request."Link Code") = "<Customer>"."No." THEN BEGIN
            ShowPDFCLient.ShowPDF();
            END;
 }
//Test request
IF (NOT (Request.MandatoryFieldsFilled)) THEN
BEGIN
//  ERROR('Missende velden!');
  //CurrReport.SKIP;
END;

IF (ReqCap MOD 19 = 0) THEN
  SLEEP(310000);

//Get Response
SOAP.FindCompanies(Request);

//Test Response
IF (NOT Request.ResultExists) THEN
BEGIN
//  ERROR('Niets gevonden');
  //CurrReport.SKIP;
END;

//Link account
//Pick the first response
Response.SETRANGE("User ID", USERID);
Response.SETRANGE("Entry No.", 1);

//MESSAGE('Dinges: %1', Response.COUNT);
IF Response.FIND('-') THEN
BEGIN
  IF Response.COUNT = 1 THEN
  BEGIN
  CreditFetchRapport.RetrieveOnlineReportProcess(Response);
    //total Counter
    TotalFound := TotalFound + 1;
    //ShowPDFCLient.ShowPDF();
  END;
END;

SLEEP(300);
 // Request.InitSearchRequest();

   //TriggerPDFDoc.GetCSAReport();

   Tools.OpenReportCard_Customer( "<Customer>"."No.");
   MESSAGE( "<Customer>"."No.");
   ShowPDFCLient.ShowPDF();

   //CreditFetchRapport.RetrieveOnlineReportProcess(Response);

    //End insert creditSafe

What PDF Contains?

Like in

CALCFIELDS(PDF);

I Know its a Blob Field as you were using Both Calcfields and Hasvalue Ok

If you just want to open File In Particular Location Then It can be Done By Shell Commands

I see that the pdf has no value:


   Tools.OpenReportCard_Customer( "<Customer>"."No.");
   //MESSAGE( "<Customer>"."No.");
   IF ShowPDFCLient.PDF.HASVALUE THEN BEGIN
   MESSAGE('has value');
   ShowPDFCLient.ShowPDF()
  END
   ELSE
   MESSAGE('not value');

Thank you for your reply. But there is a button that the function ShowPDF triggers. And that works. But I want to trigger that function after import

Hi,
Are you first importing data and the running it right after?
Have you any commits in the code? Although I normally warn against commits, then in this case that could maybe be the issue. Also if the report can be triggered manually also, then a commit after you finish handling the import data, could prevent at roll-back if the pdf-function fails.

This is the function under the button:


Setup.Read;
IF  PDF.HASVALUE THEN BEGIN
  MESSAGE('HAShVALUE')
   END
  ELSE
  MESSAGE('no value');


CALCFIELDS(PDF);
IF NOT PDF.HASVALUE THEN BEGIN
  TESTFIELD(PDF);
END;
PDF.CREATEINSTREAM(InStream);

Tools.ShowPDF(InStream);

Yes, I do a import and then running the pdf

Then try with a COMMIT after you have imported, before calling the pdf function.

You mean like this:


//MESSAGE('Dinges: %1', Response.COUNT);
IF Response.FIND('-') THEN
BEGIN
  IF Response.COUNT = 1 THEN
  BEGIN
  CreditFetchRapport.RetrieveOnlineReportProcess(Response);
    //total Counter
    TotalFound := TotalFound + 1;
    //ShowPDFCLient.ShowPDF();
  END;
END;

SLEEP(300);
 COMMIT;
   Tools.OpenReportCard_Customer( "<Customer>"."No.");
  Request."Link Type" := Request."Link Type"::customer;
   IF ShowPDFCLient.PDF.HASVALUE THEN BEGIN
   MESSAGE('has value');
   ShowPDFCLient.ShowPDF()
  END
   ELSE
   MESSAGE('not value');

But still the value is hasnovalue

Let me see if I fully understand the issue right now:

  1. You can run the function to import the lines. After import you can manually show the pdf file with the ShowPDF function.
  2. If you run the function directly, in the context of the import function, then it the PDF field shows as having no data? And if it fails to show, then you can still show it manually after?

If that is correct, then I understand that you are puzzled. Me too.

You have showed a lot of your code. But where do you actually sets the value of the showpdfclient pdf blob field?

Also looking at the code in the reply above, then where did you GET the ShowPDFClient record. After you get it, then before HASVALUE, did you CALCFIELDS(PDF) first?

Hi Erik, I added a image. Because afterwards you have a button where you can create a pdf file of the document(credit safe)

If I do it like this:


//MESSAGE('Dinges: %1', Response.COUNT);
IF Response.FIND('-') THEN
BEGIN
  IF Response.COUNT = 1 THEN
  BEGIN
  CreditFetchRapport.RetrieveOnlineReportProcess(Response);
    //total Counter
    TotalFound := TotalFound + 1;
    //ShowPDFCLient.ShowPDF();
  END;
END;

SLEEP(300);
 COMMIT;
  Tools.OpenReportCard_Customer( "<Customer>"."No.");
  Request."Link Type" := Request."Link Type"::customer;
  ShowPDFCLient.CALCFIELDS(PDF);
  //MESSAGE(ShowPDFCLient."CS Company Name");
   IF ShowPDFCLient.PDF.HASVALUE THEN BEGIN
   MESSAGE('has value');
   ShowPDFCLient.ShowPDF()
  END
   ELSE
   MESSAGE('not value');

I get the message that I have to declare CLACFIELDS in globals? But CALCFUNCTION is a function

What is calcfunction?

I mean where is the ShowPDFClient.GET of FIND?

IF ISSERVICETIER THEN BEGIN
  Filename := GetTempFilename('pdf');
  DOWNLOADFROMSTREAM(InStream,'',FileManagement.Magicpath,Text010,Filename);

END ELSE BEGIN
  File.CREATETEMPFILE;
  Filename := File.NAME + '.pdf';
  File.CLOSE;

  File.CREATE(Filename);
  File.CREATEOUTSTREAM(OutStream);
  COPYSTREAM(OutStream,InStream);
  File.CLOSE;
END;

HYPERLINK(Filename);

After the function ShowPDF() it goes to: this function:

Niels/Zodiac,

I really like to help you out, but you make it very difficult if you don’t start answering the questions asked, in the previous reply.

So let me give you those questions again:

Let me see if I fully understand the issue right now:

1) You can run the function to import the lines. After import you can manually show the pdf file with the ShowPDF function.

2) If you run the function directly, in the context of the import function, then it the PDF field shows as having no data? And if it fails to show, then you can still show it manually after?

If that is correct, then I understand that you are puzzled. Me too.

Is this assumption correction?

You have showed a lot of your code. But where do you actually sets the value of the showpdfclient pdf blob field?

Also looking at the code in the reply above, then where did you GET the ShowPDFClient record. After you get it, then before HASVALUE, did you CALCFIELDS(PDF) first?

I’m not really interested in what happens in the function you wrote (as I read it) works. I like to know why there is no value in the pdf blob field.

If that is correct, then I understand that you are puzzled. Me too.

Yes. Because there is a button. you can see it in the image I posted. If you trigger that button a pdf will be shown. But if you do it in the XML port the PDF is empty and no pdf will be shown.

  • CALCFIELDS(PDF) that is part of that function(ShowPDF())

Yes I understand that. But please show me the code where you GET or FIND or INSERT or in what other way you populate the table containing the BLOB field that you have your PDF file in. Especially where you stream the data into the field, to where you check its value.

This is the table:

And this is the code of the table:


Documentation()

OnInsert()
IF EntryNo = 0 THEN BEGIN
  EntryNo := GetNextNo();
END;

Changed(TRUE);

OnModify()
Changed(FALSE);

OnDelete()
ReportDetails.RESET;
ReportDetails.SETRANGE(EntryNo, EntryNo);
ReportDetails.DELETEALL(TRUE);

OnRename()
Changed(FALSE);

EntryNo - OnValidate()

EntryNo - OnLookup()

Active Report - OnValidate()

Active Report - OnLookup()

Creditsafe ID - OnValidate()

Creditsafe ID - OnLookup()

Language - OnValidate()

Language - OnLookup()

Report Type - OnValidate()

Report Type - OnLookup()

Request Reason - OnValidate()

Request Reason - OnLookup()

Charge Reference - OnValidate()

Charge Reference - OnLookup()

RegistrationNo - OnValidate()

RegistrationNo - OnLookup()

Country - OnValidate()

Country - OnLookup()

NAV Country - OnValidate()

NAV Country - OnLookup()

Tradename - OnValidate()

Tradename - OnLookup()

CS Company Name - OnValidate()

CS Company Name - OnLookup()

Address Single Value - OnValidate()

Address Single Value - OnLookup()

Street - OnValidate()

Street - OnLookup()

House No. - OnValidate()

House No. - OnLookup()

NAV Address - OnValidate()

NAV Address - OnLookup()

Post Code - OnValidate()

Post Code - OnLookup()

City - OnValidate()

City - OnLookup()

PhoneNo - OnValidate()

PhoneNo - OnLookup()

VAT ID - OnValidate()

VAT ID - OnLookup()

NAV VAT ID - OnValidate()

NAV VAT ID - OnLookup()

Legalform - OnValidate()

Legalform - OnLookup()

CommercialCourt - OnValidate()

CommercialCourt - OnLookup()

CompanyStatus - OnValidate()

CompanyStatus - OnLookup()

MainActivity - OnValidate()

MainActivity - OnLookup()

CommonCreditRating - OnValidate()

CommonCreditRating - OnLookup()

CommonCreditRatingDescription - OnValidate()

CommonCreditRatingDescription - OnLookup()

CreditLimit - OnValidate()

CreditLimit - OnLookup()

ProviderCreditRating - OnValidate()

ProviderCreditRating - OnLookup()

ProviderRatingDescription - OnValidate()

ProviderRatingDescription - OnLookup()

OrderNo - OnValidate()

OrderNo - OnLookup()

DECurrentRating - OnValidate()

DECurrentRating - OnLookup()

UltimateParent - OnValidate()

UltimateParent - OnLookup()

ImmediateParent - OnValidate()

ImmediateParent - OnLookup()

LastCreditRatingChange - OnValidate()

LastCreditRatingChange - OnLookup()

Turnover Range - OnValidate()

Turnover Range - OnLookup()

No. of Links - OnValidate()

No. of Links - OnLookup()

First Linked Contact - OnValidate()

First Linked Contact - OnLookup()

First Linked Customer - OnValidate()

First Linked Customer - OnLookup()

First Linked Vendor - OnValidate()

First Linked Vendor - OnLookup()

No. of Portfolios - OnValidate()

No. of Portfolios - OnLookup()

PDF - OnValidate()

PDF - OnLookup()

TrafficLightImage - OnValidate()

TrafficLightImage - OnLookup()

CreationDateTime - OnValidate()

CreationDateTime - OnLookup()

CreationDate - OnValidate()

CreationDate - OnLookup()

CreatedBy - OnValidate()

CreatedBy - OnLookup()

ModificationDate - OnValidate()

ModificationDate - OnLookup()

ModifiedBy - OnValidate()

ModifiedBy - OnLookup()

Changed(vbn_Insert : Boolean)
IF vbn_Insert THEN BEGIN
  CreationDateTime := CURRENTDATETIME;
  CreationDate := TODAY;
  CreatedBy := USERID;
END;

ModificationDate := CURRENTDATETIME;
ModifiedBy := USERID;

GetNextNo() : Integer
IF Report.FINDLAST THEN;
EXIT(Report.EntryNo + 1);

ShowHistory(ParReport : Record "CSA - Report")
Report.SETRANGE("Creditsafe ID", ParReport."Creditsafe ID");

ReportList.SetHistoryMode(TRUE);
ReportList.SETRECORD(Report);
ReportList.SETTABLEVIEW(Report);
ReportList.RUN;

FirstPortfolioName() : Text[30]
CLEAR(PortfolioCompany);
PortfolioCompany.SETRANGE("Creditsafe ID","Creditsafe ID");
IF PortfolioCompany.FINDFIRST THEN BEGIN
  Portfolio.SETRANGE(ID,PortfolioCompany."Portfolio ID");
  Portfolio.FINDFIRST;
  EXIT(Portfolio.Name);
END;

--- PDF Functions ---()

ShowPDF()
Setup.Read;

IF  PDF.HASVALUE THEN BEGIN
  MESSAGE('HAShVALUE');
   END
  ELSE
  MESSAGE('no value');


CALCFIELDS(PDF);
IF NOT PDF.HASVALUE THEN BEGIN
  TESTFIELD(PDF);
END;
PDF.CREATEINSTREAM(InStream);

Tools.ShowPDF(InStream);

--- Link Functions ---()

CreateCustomer(Report : Record "CSA - Report")
Setup.Read;

//Get Customer Template
IF Setup."Use Customer Templates" THEN BEGIN
  CustomerTemplateList.LOOKUPMODE(TRUE);
  IF NOT CustomerTemplate.ISEMPTY THEN BEGIN
    IF CustomerTemplateList.RUNMODAL = ACTION::LookupOK THEN BEGIN
      CustomerTemplateList.GETRECORD(CustomerTemplate);
    END;
  END;
END;

WITH Customer DO BEGIN

  RESET;
  INIT;
  INSERT(TRUE);

  //Apply Customer Template
  IF CustomerTemplate.Code <> '' THEN BEGIN
    "Territory Code" := CustomerTemplate."Territory Code";
    "Currency Code" := CustomerTemplate."Currency Code";
    "Country/Region Code" := CustomerTemplate."Country/Region Code";
    "Customer Posting Group" := CustomerTemplate."Customer Posting Group";
    "Customer Price Group" := CustomerTemplate."Customer Price Group";
    "Invoice Disc. Code" := CustomerTemplate."Invoice Disc. Code";
    "Customer Disc. Group" := CustomerTemplate."Customer Disc. Group";
    "Allow Line Disc." := CustomerTemplate."Allow Line Disc.";
    "Gen. Bus. Posting Group" := CustomerTemplate."Gen. Bus. Posting Group";
    "VAT Bus. Posting Group" := CustomerTemplate."VAT Bus. Posting Group";
    "Payment Terms Code" := CustomerTemplate."Payment Terms Code";
    "Payment Method Code" := CustomerTemplate."Payment Method Code";
    "Shipment Method Code" := CustomerTemplate."Shipment Method Code";
    MODIFY;

    DefaultDimensionTemplate.SETRANGE("Table ID", DATABASE::"Customer Template");
    DefaultDimensionTemplate.SETRANGE("No.", CustomerTemplate.Code);
    IF DefaultDimensionTemplate.FINDSET(FALSE, FALSE) THEN
      REPEAT
        CLEAR(DefaultDimensionCustomer);
        DefaultDimensionCustomer.INIT;
        DefaultDimensionCustomer.VALIDATE("Table ID", DATABASE::Customer);
        DefaultDimensionCustomer."No." := Customer."No.";
        DefaultDimensionCustomer.VALIDATE("Dimension Code", DefaultDimensionTemplate."Dimension Code");
        DefaultDimensionCustomer.VALIDATE("Dimension Value Code", DefaultDimensionTemplate."Dimension Value Code");
        DefaultDimensionCustomer."Value Posting" := DefaultDimensionTemplate."Value Posting";
        DefaultDimensionCustomer.INSERT(TRUE);
      UNTIL DefaultDimensionTemplate.NEXT = 0;
  END;
END;

ReportAllocation.AllocateReportToLink(Report, ReportAllocation."Link Type"::customer, Customer."No.");
Tools.SyncAddressCustomerReport(Customer,Report,FALSE);

CustContUpdate.OnInsert(Customer);

RecRef.GETTABLE(Customer);
Tools.Changelog_Insert(RecRef);

IF GUIALLOWED THEN BEGIN
  MESSAGE(Text001, FORMAT(ReportAllocation."Link Type"::customer), Customer."No.");
END;

Tools.AskEditCustomer(Customer);

CreateVendor(Report : Record "CSA - Report")
Vendor.RESET;
Vendor.INIT;
Vendor.INSERT(TRUE);

ReportAllocation.AllocateReportToLink(Report,ReportAllocation."Link Type"::vendor,Vendor."No.");
Tools.SyncAddressVendorReport(Vendor,Report,FALSE);

RecRef.GETTABLE(Vendor);
Tools.Changelog_Insert(RecRef);

VendContUpdate.OnInsert(Vendor);

IF GUIALLOWED THEN BEGIN
  MESSAGE(Text001, FORMAT(ReportAllocation."Link Type"::vendor), Vendor."No.");
END;

Tools.AskEditVendor(Vendor);

CreateContact(Report : Record "CSA - Report")
Contact.RESET;
Contact.INIT;
Contact.INSERT(TRUE);

ReportAllocation.AllocateReportToLink(Report,ReportAllocation."Link Type"::contact,Contact."No.");
Tools.SyncAddressContactReport(Contact,Report,FALSE);

RecRef.GETTABLE(Contact);
Tools.Changelog_Insert(RecRef);

Contact.TypeChange();

IF GUIALLOWED THEN BEGIN
  MESSAGE(Text001, FORMAT(ReportAllocation."Link Type"::contact), Contact."No.");
END;

Tools.AskEditContact(Contact);

MyCopyStr(vtx_FromStr : Text[1024];vin_MaxToStrLen : Integer) : Text[1024]
EXIT(COPYSTR(vtx_FromStr, 1, vin_MaxToStrLen));

GetTrafficLightImage(VAR Report : Record "CSA - Report")
IF Report."Creditsafe ID" = '' THEN BEGIN
  EXIT;
END;

IF Report.ProviderCreditRating = '' THEN BEGIN
  EXIT;
END;

WITH TrafficLightSetup DO BEGIN
  CLEAR(TrafficLightSetup);
  IF EVALUATE(lin_IntValue, Report.ProviderCreditRating) THEN BEGIN
    SETFILTER("Provider Creditrating Int From", '<=%1', lin_IntValue);
    SETRANGE("Provider Creditrating Text", '');
  END ELSE BEGIN
    SETRANGE("Provider Creditrating Int From", 0);
    SETRANGE("Provider Creditrating Text", Report.ProviderCreditRating);
  END;
  IF NOT FINDLAST THEN BEGIN
    SETRANGE("Provider Creditrating Text",'');
  END;
  IF FINDLAST THEN BEGIN
    CALCFIELDS("Traffic Light Image");
    IF NOT "Traffic Light Image".HASVALUE THEN BEGIN
      EXIT;
    END;
    Report.TrafficLightImage.CREATEOUTSTREAM(los_OutStream);
    "Traffic Light Image".CREATEINSTREAM(lis_InStream);
    COPYSTREAM(los_OutStream, lis_InStream);
  END;
END;