Customization Button

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’.


any suggestions what his should be?

You need to add this to your usings if not there already

using Ice.Core;

Then to get the current user id it would be this

edvMaintReq.dataView[edvMaintReq.Row]["ShortChar02"] = ((Session)oTrans.Session).UserID;
1 Like

Thanks I forgot about the Ice.Core.

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…

Where is edvMaintReq getting instantiated? Can you include the entire customization code?

Is this what you are looking for?

// **************************************************
// 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;
}

}

I would check the name of the EpiDataView as it might not be “MaintReq”. I don’t have the Maint module to check.

edvMaintReq = (EpiDataView)oTrans.EpiDataViews["MaintReq"];
1 Like
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:


private EpiDataView edvMaintReqView;


this.edvMaintReqView = ((EpiDataView)(this.oTrans.EpiDataViews["MaintReqView"]));

Did you use a wizard to create your code ?

Pierre

1 Like

yes, I did.

But as I was working on this this found out that this will not work for what they need…so back to basic.

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.

Pierre