Customized report naming?

Got it down to 1 BPM !

You can remove the previous ones, and control it all from one BPM.
Haven’t tested in Kinetic yet, it’s possible it behaves differently.

Post-Processing BPM on Ice.BO.ReportMonitor.Update

/***************************************************************************************
Post-Processing BPM on Ice.BO.ReportMonitor.Update 
Author: Kevin Lincecum
Purpose: Renames files previewed from the System Monitor to a custom format based on
  criteria from the SysTaskParam table.
***************************************************************************************/

try
{
    //Isolate rows for processing based on these criteria
    var rowsForProcessing = ds.SysRptLst.Where(x =>
        x.PrintDriver == "SSRS" &&
        x.LastAction == "Process");

    //Loop through each selected row 
    foreach(SysRptLstRow sysRptLstRow in rowsForProcessing)
    {
        //Pull out for convenience / readability
        long sysTaskNum = sysRptLstRow.SysTaskNum;
        
        //Get all the Parameters for this report 
        List<SysTaskParam> sysTaskParams = Db.SysTaskParam.Where(stp => stp.SysTaskNum == sysTaskNum).ToList();
        
        //Get the Report ID
        string reportID = sysTaskParams.Where(stp => stp.ParamName == "ReportID").FirstOrDefault().ParamCharacter;
        
        //Get the Report Parameter DataSetID
        //string reportParameterDataSetId = sysTaskParams.Where(stp => stp.ParamName == "ReportParameterDataSetId").FirstOrDefault().ParamCharacter;
        
        //Checks based off of the "ReportID", so you could handle different kinds of reports etc.
        if(reportID == "OrderAck")
        //Or you could check the "ReportParameterDataSetId"
        //if(reportParameterDataSetId == "SalesOrderAck")
        {
            //Get the Report Style so you can check against it.. 
            int reportStyleNum = sysTaskParams.Where(stp => stp.ParamName == "ReportStyleNum").FirstOrDefault().ParamInteger;
            
            //Get the Order Number so we can pull further data..
            int orderNum       = sysTaskParams.Where(stp => stp.ParamName == "OrderNum").FirstOrDefault().ParamInteger;
            
            //I wanted the Customer ID, but we need to get the Customer Number first...
            int custNum = Db.OrderHed.Where(o => o.Company == Session.CompanyID && o.OrderNum == orderNum).FirstOrDefault().CustNum;
            
            //Get the Customer ID
            string custID = Db.Customer.Where(c => c.Company == Session.CompanyID && c.CustNum == custNum).FirstOrDefault().CustID;
            
            //Do different types of actions based on which Report Style is passed, use your imagination.
            switch(reportStyleNum)
            {
                case 2:
                    sysRptLstRow.RptDescription = $"Blistering_Donkey-{orderNum.ToString()}_CustID-{custID}";
                    break;
                    
                case 1001:
                    sysRptLstRow.RptDescription = $"Voluptuous_Mole-Rat-{orderNum.ToString()}_CustID-{custID}";
                    break;
                    
                default:
                    sysRptLstRow.RptDescription = $"I_LIKE_TURTLES";
                    break;
            }
            
            //Below is what is appended to the end of the filename.
            //Making the best of what you can do...
            
            //This will be "0";
            sysRptLstRow.SetSysTaskNumUnspecified();
            
            //Or set it to Ticks for something useful & unique 
            //sysRptLstRow.SysTaskNum = DateTime.Now.Ticks;            
            
            //Or set it to OrderNum, might be useful
            //sysRptLstRow.SysTaskNum = orderNum;
        }
    }
}
catch (Exception ex)
{
    //Do whatever you do with errors...
}
10 Likes