Quote PDF as a Base64 string via a REST BAQ call

I am working in 10.2.700.40 and I trying to create an API of sorts to connect with a third party software via direct link. Once we get into SaaS, this will be MUCH easier. However, for the itme being, I need this working. Below are the steps I took to get to where I am . Bascially, I’ve set up an Function to handle the report generation and a Post-Processing BPM on ExecuteByID to bridge the data, but the BAQ result remains blank.

Fucntion: Used the Assembly Erp.Contracts.Rpt.QuotForm.dll and the Quote services.
Named it GetQuotePDF

string uniqueStamp = Guid.NewGuid().ToString();

// Calls the Quote Report Service
this.CallService<Erp.Contracts.QuotFormSvcContract>(svcQuote => {
    var tsQuote = svcQuote.GetNewParameters();
    
    tsQuote.QuoteFormParam[0].QuoteNum = quotenum; // Input parameter
    tsQuote.QuoteFormParam[0].ReportStyleNum = [YourStyleNum]; 
    tsQuote.QuoteFormParam[0].TaskNote = uniqueStamp;
    tsQuote.QuoteFormParam[0].AutoAction = "SSRSGenerate";
    tsQuote.QuoteFormParam[0].AgentID = "SystemTaskAgent";
    
    svcQuote.RunDirect(tsQuote);
});

// Polling loop to wait for Task Agent
int attempts = 0;
bool found = false;
var reportRecord = (dynamic)null;

while (attempts < 15 && !found)
{
    System.Threading.Thread.Sleep(1000); 
    
    reportRecord = (from srl in this.Db.SysRptLst
                    join st in this.Db.SysTask on srl.SysTaskNum equals st.SysTaskNum
                    where st.TaskNote == uniqueStamp
                    select srl).FirstOrDefault();
                    
    if (reportRecord != null && reportRecord.RptData != null)
    {
        found = true;
    }
    attempts++;
}

if (found)
{
    pdfBase64 = Convert.ToBase64String(reportRecord.RptData); // Output parameter
}
else
{
    throw new Exception("Timeout: PDF not found in SysRptLst after 15 seconds.");
}

BAQ had the table Ice.SysCompany with only company in the field. Hoping to ensure a response. Calc Field: PdfBase64 (Type: nvarchar, Format: x(max), Editor: ‘’).
BPM is a post processing on Ice.BO.DynamicQuery.ExecuteByID.

// Debug message to confirm activation
this.PublishInfoMessage("BPM Active. QueryID: [" + queryID + "]", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

if (!queryID.Equals("[YourBAQID]", StringComparison.OrdinalIgnoreCase))
{
    return;
}

string quoteNumStr = "0";
if (executionParams != null)
{
    foreach (var param in executionParams.ExecutionParameter)
    {
        if (param.ParameterID.Equals("quoteNum", StringComparison.OrdinalIgnoreCase))
        {
            quoteNumStr = param.ParameterValue;
            break;
        }
    }
}

// Clean up commas from UI auto-formatting
int quoteNum = 0;
string cleanQuoteNumStr = (quoteNumStr ?? "0").Replace(",", "");
int.TryParse(cleanQuoteNumStr, out quoteNum);

string pdfBase = "";
var efxResult = this.InvokeFunction("[YourLibraryName]", "GetQuotePDF", Tuple.Create(quoteNum));
if (efxResult != null)
{
    var resultTuple = efxResult as Tuple<string>;
    if (resultTuple != null) { pdfBase = resultTuple.Item1 ?? ""; }
}

if (result != null && result.Tables.Count > 0)
{
    foreach (System.Data.DataRow row in result.Tables[0].Rows)
    {
        if (!string.IsNullOrEmpty(pdfBase))
        {
            row["Calculated_PdfBase64"] = pdfBase;
        }
    }
}

Issue: Even though the debug message fires, the PdfBase64 column is empty.

You can simplify that report function. No need to poll for report generation when using rundirect. It will exist or not when that returns.

On to your issue.

Have you verified the function itself is working?

On my phone, but still trying to help lol.

Also, I’m not sure if this was. debugging step, but the bpm on ExecuteByID, is overkill.

Make your BAQ itself updatable and add a bpm to the baq itself.

The first several iterations were simple, but went overboard with debugging as nothing was working. Brain fried for sure.

I was thinking of putting the bpm in the baq.

Can you explain why to make it updateable? Is it so the basepdf64 can be written too? However this is just a calc field and not a ud field.

Appreciate the help!

1 Like

Making it updateable gives you access to the baq BPMs it doesn’t mean you have to update anything in your baq. Just use the advance BPM only option instead of choosing a method when you make it updateable.

1 Like

Yep…brain fried with nearly tunnel vision. Going to go that direction. Looks much cleaner. Thank you.

Just to be clear so no one gets confused in the future. You can still use the regular non advanced, and use a business object like a normal ubaq. (If you need to) It’s just the base method is auto generated and can and will be overwritten with changes.

You can still add other methods for your own use.

You still didn’t answer if you’ve just tested the function.

Start there, and then we’ll work on the rest.

Looks for GetReportBytes

https://www.epiusers.help/search?q=GetReportBytes%20order%3Alatest

1 Like

I did check it and seemed to be working and promoted. Is there a specific way of testing that you have in mind