Job Traveler Attachment Printing - 10.2

Here’s the way we did this, I can provide some code but since this particular to us I don’t really want to upload the whole thing and cause confusion.

  1. We wrote a simple BAQ that returns Jobs Ready to Print (whatever criteria you want)
  2. Then we Added a Button which for each selected Job in the Grid Invokes the Job Traveler Print.
	foreach(var row in myGrid.Rows)
				{
					if((bool)row.Cells["Calculated_Print"].Value)
					{
						var jobTravDs = jobTravSvc.GetNewParameters();
						var jobTravParamRecord = jobTravDs.JobTravParam[0];
						jobTravParamRecord.AgentID = "SystemTaskAgent";
			            jobTravParamRecord.AutoAction = "SSRSGenerate";
			            jobTravParamRecord.BarCodes = true;
			            jobTravParamRecord.Jobs = row.Cells["JobHead_JobNum"].Value as String;
			            jobTravParamRecord.NewPgPerAsm = true;
			            jobTravParamRecord.OpInstructions = true;
			            jobTravParamRecord.OprDates = true;
			            jobTravParamRecord.OprStd = true;
			            jobTravParamRecord.PrintSchedResources = true;
			            jobTravParamRecord.PrintSchedResrcDesc = true;
			            jobTravParamRecord.SSRSRenderFormat = "PDF";
			            jobTravParamRecord.SubAssem = true;
						jobTravParamRecord.SSRSEnableRouting = false;
			            jobTravParamRecord.TaskNote = instanceGuid.ToString();
						jobTravSvc.SubmitToAgent(jobTravDs,"SystemTaskAgent",0,0,"Erp.UIRpt.JobTrav");
						InvokeMsg(string.Format("Running Job Traveler for Job: {0}",   jobTravParamRecord.Jobs));
					}
				}

One of the things we do here is tag the “TaskNote” with a unique identifier to make it easier to find these jobs. We then wait until those jobs are done processing, this can take some time we wrote a BAQ that just checks to see how many of the Tasks with that “Unique ID” are still “ACTIVE” and we wait a few seconds and check again.

Once all those job travelers are done processing.
We run a BAQ that returns the generated Report SysRow ID along with the job Number from the Task

select 
	[SysRptLst].[Company] as [SysRptLst_Company],
	(ISNULL(((select 
	(COUNT(SysTaskCt.SysTaskNum)) as [Calculated_CT]
from Ice.SysTask as SysTaskCt
where (SysTaskCt.TaskStatus in ('ACTIVE', 'PENDING')  and SysTaskCt.TaskNote = @TaskNote))),0)) as [Calculated_PendingCt],
	[SysRptLst].[SysRowID] as [SysRptLst_SysRowID],
	[SysTask].[TaskNote] as [SysTask_TaskNote],
	[SysTaskParam].[ParamCharacter] as [SysTaskParam_ParamCharacter]
from Ice.SysTask as SysTask
inner join Ice.SysRptLst as SysRptLst on 
	SysTask.Company = SysRptLst.Company
	and SysTask.SysTaskNum = SysRptLst.SysTaskNum
inner join Ice.SysTaskParam as SysTaskParam on 
	SysTask.SysTaskNum = SysTaskParam.SysTaskNum
	and ( SysTaskParam.ParamName = 'Jobs'  )

where (SysTask.TaskStatus in ('COMPLETE')  and SysTask.TaskNote like '%'+ @TaskNote+'%')
 and ((ISNULL(((select 
	(COUNT(SysTaskCt.SysTaskNum)) as [Calculated_CT]
from Ice.SysTask as SysTaskCt
where (SysTaskCt.TaskStatus in ('ACTIVE', 'PENDING')  and SysTaskCt.TaskNote = @TaskNote))),0)) = 0)

We then use that to retrieve the Report Content using the ReportMonitorAdapter , retrieve the Report Bytes and write it to a TempFile

using(ReportMonitorAdapter rmA = new ReportMonitorAdapter(oTrans))
					{
						rmA.BOConnect();
						foreach(DataRow dr in ranTravelers.Tables["Results"].Rows)
						{
							List<string> fileNames = new List<string>();
							byte[] rptData=rmA.GetReportBytes((Guid)dr["SysRptLst_SysRowID"]);
			 			   var tempPath = Path.GetTempPath();
							string fileName = Path.Combine(tempPath, string.Format("{0}.pdf",dr["SysRptLst_SysRowID"]));
							File.WriteAllBytes(fileName, rptData);

We then use a BAQ that returns all attachments from a given job and we use the attachmentService to Download / Retrieve the file and write it to a Temporary Location

	foreach(DataRow drAttch in dsAttch.Tables["Results"].Rows)
							{
								InvokeMsg(string.Format("Processing Attachment {0} of {1}",ct,dsAttch.Tables[0].Rows.Count));	
								Dictionary<String,String> metaData = new Dictionary<String,String>();
								byte[] attchData = attachmentSvc.DocStarDownloadFile((int)drAttch["XFileRef_XFileRefNum"], ref metaData);
								string fn = Path.Combine(tempPath, string.Format("{0}.pdf", Guid.NewGuid()));
								File.WriteAllBytes(fn, attchData);
								fileNames.Add(fn);
							}

Finally we send all the files to the printer in order in which they were created.

4 Likes