I have a deployed dashboard assembly that I would like to customize to add a button that allows a file to be attached to the Part record. Tracing the New Attachment process scared me off, until I came across Jose’s one line of code to attach a file:
https://www.epiusers.help/t/code-from-meug-presentation-on-5-20-2020-customization-tips-and-tricks/67376
But, it doesn’t work for me. I created a button on the tracker view, I think I captured the dataview of one selected row. I have AttachmentHandler.DropNewAttachment in code and it does not generate an error. But, it does not create the attachment on the Part record as I hoped.
Perhaps this simple one line code does not work with Dashboards, only in out-of-box forms?
Or perhaps I need to more directly indicate that it is the Part record that I want to attach the file to (and the “ROHS” Document Type ID if possible)?
We do not have any 3rd party document software, and we don’t use Sharepoint, just basic Epicor functionality pointing to Windows File System documents.
Here’s my Dashboard:
Here’s my code:
Summary
// **************************************************
// Custom code for MainController
// Created: 3/8/2023 9:01:34 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.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;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
private EpiDataView edvV_PP_ROHSUpdate_1View;
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
this.edvV_PP_ROHSUpdate_1View = ((EpiDataView)(this.oTrans.EpiDataViews["V_PP_ROHSUpdate_1View"]));
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
this.edvV_PP_ROHSUpdate_1View = null;
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
using(OpenFileDialog ofd = new OpenFileDialog())
{
if(ofd.ShowDialog()==DialogResult.OK)
{
var currentEdv = ((EpiDataView)(this.oTrans.EpiDataViews["V_PP_ROHSUpdate_1View"]));
String PartNumSelected = Convert.ToString(currentEdv.dataView.Table.Rows[currentEdv.Row]["Part_PartNum"]);
MessageBox.Show(ofd.FileName);
MessageBox.Show(PartNumSelected);
AttachmentHandler.DropNewAttachment(MainController,ofd.FileName,currentEdv.dataView.Table.Rows[currentEdv.Row],"ROHS");
}
}
}
Any suggestions or advice? Or should I give up on this one line of code approach?
(If it is not obvious, I can copy code I find, but I’m no programmer)