I have created a button on the the Maintenance Request Entry. When the user clicks this it should populate their name. Evidently I am calling the wrong thing and this is not my strong point. There error doesn’t like ‘session’.
When I tested the code it said it complied successfully. But when I launch the customization I get and Object reference not set to and instance of an object. I can click ok past it but when I click on the submit button the error pops up…
// **************************************************
// Custom code for MaintReqForm
// Created: 8/6/2018 8:14:09 AM
// **************************************************
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 Ice.Core;
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 edvMaintReq;
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
this.btnSubmittedby.Click += new System.EventHandler(this.btnSubmittedby_Click);
// End Wizard Added Custom Method Calls
edvMaintReq = (EpiDataView)oTrans.EpiDataViews["MaintReq"];
edvMaintReq.dataView.Table.Columns["ShotChar02"].ExtendedProperties["ReadOnly"] = true;
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.btnSubmittedby.Click -= new System.EventHandler(this.btnSubmittedby_Click);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void btnSubmittedby_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
edvMaintReq.dataView[edvMaintReq.Row]["ShortChar02"]= ((Session)oTrans.Session).UserID;
}
edvMaintReq.dataView[edvMaintReq.Row]["ShortChar02"]=(Ice.Core.Session)oTrans.Session.EmployeeID.ToString();
//or for the user name:
edvMaintReq.dataView[edvMaintReq.Row]["ShortChar02"]=(Ice.Core.Session)oTrans.Session.UserName.ToString();
That is if using E10…which your tag in the title indicates…
But I went into my maintenance request module and here is how it was declared using the wizard:
Another way could be by using a data directive, when a new record in MaintReq is created, save the current user into your ud field. as the creator or the request.