Job Traveler Print Attachment

Hello Everybody,

I’ve recently been asked to create a system in our job traveler to print attachments with the report, pulled from the Job entry module. Using Epiusers I was able to get my hands on some code to customize the form, but I am running into a strange error and am having trouble debugging.

I have somewhat of a programming background, but am very new and unfamiliar to the operations of Epicor, so any help would be greatly appreciated!

<extern alias Erp_Contracts_BO_JobAsmSearch;
extern alias Erp_Contracts_BO_JobEntry;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using System.IO;
using System.Collections.Generic;
using Erp.BO;
using System.Text;
using Ice.Core;
using Erp.Proxy.BO;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	private EpiDataView edvJobList;
	private EpiDataView edvAsmList;

	StringBuilder Texte = new StringBuilder();

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls

		edvJobList = ((EpiDataView)(this.oTrans.EpiDataViews["jobList"]));
		edvAsmList = ((EpiDataView)(this.oTrans.EpiDataViews["assemblyList"]));
		
		this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
		
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal
		edvJobList = null;
		edvAsmList = null;
		this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
		Texte = null;
		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
		
	}

	private void JobTravForm_Load(object sender, EventArgs args)
	{
		SetVersionNumber(JobTravForm);
	}

	private void SetVersionNumber(EpiBaseForm form)
	{
		string custName = oTrans.EpiBaseForm.CustomizationName;
		string version = "Edit";
		if (custName.LastIndexOf("_") >= 0)
		{
			version = custName.Substring(custName.LastIndexOf("_") + 1, custName.Length - custName.LastIndexOf("_") - 1);
		}
		form.Text = form.Text + " - Peter Adams " + version;
	}

	private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
		if (edvJobList.dataView.Table.Rows.Count > 0)
		{
			Ice.Core.Session epiSession = default(Ice.Core.Session);
			epiSession = (Ice.Core.Session)JobTravForm.Session;

			JobEntryAdapter JobEntryBO = new JobEntryAdapter((Ice.Core.Session)oTrans.Session);

			DataTable tempTable = new DataTable();
			tempTable.Columns.Add("JobNum", typeof(string));
			tempTable.Columns.Add("PartNum", typeof(string));
			tempTable.Columns.Add("FileName", typeof(string));
			tempTable.Columns.Add("AsmSeq", typeof(string));
			tempTable.Columns.Add("ParentPart", typeof(string));

			foreach (var value in tempTable.Columns)
			{
			MessageBox.Show(value.ToString());
     	   }
			for(int x=0; x < edvJobList.dataView.Table.Rows.Count; x++)
			{
				Ice.Lib.Searches.SearchOptions opts = new Ice.Lib.Searches.SearchOptions(SearchMode.AutoSearch);
				string whereClause = string.Format("JobNum = '" + edvJobList.dataView.Table.Rows[x]["JobNum"].ToString() + "'");
				opts.PageSize = 0;
				opts.AbsolutePage = 1;
				opts.NamedSearch.WhereClauses.Add("JobHead",whereClause);
				opts.DataSetMode = Ice.Lib.Searches.DataSetMode.RowsDataSet;
				bool morePages = false;
		
				var jobEntryDS = (Erp.BO.JobEntryDataSet)JobEntryBO.GetRows(opts,out morePages);
				foreach(DataRow hr in jobEntryDS.Tables["JobHead"].Rows)
				{
					MessageBox.Show(hr["JobNum"].ToString());
				}
			}
		}
		
		else
		{
			MessageBox.Show("Test");
		}
	}
}>

Adapter instantiation expects oTrans not a session I’m really sure why (or what) you are doing here. You are taking a session object and “Defaulting it” then taking the Session Object attached to the Form and passing it into the Adapter?

That doesn’t make a ton of sense, anyways the adapter expects a Transaction object that implements iLaunch or an instance of the current for which also implements iLaunch.

Thanks for the response Jose!

Makes a bit more sense when you break it down, I was also unsure but mostly following other codes to help me get on my feet.
The idea was to create a new session when the user selects a button, but probably not a good idea (or optimal) in hindsight.

Regardless, thank you for the info! I’ll make those adjustments now.