I am using below code to Enable or Disable the User account. It is working in script editor but while using the similar code in Epicor function maintenance then it is not working.
Script Editor
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
adapterUserFile.BOConnect();
bool objds = adapterUserFile.GetByID(“Test”);
//var user = ds.UserFile.FirstOrDefault();
if(objds)
{
adapterUserFile.UserFileData.Tables[“UserFile”].Rows[0][“UserDisabled”] = “false”;
adapterUserFile.Update();
}
adapterUserFile.Dispose();
I’ve got something like this running in production as part of our offboarding process. I used UpdateExt to bypass some annoying errors. It required a service account with admin privileges to actually work, since admin rights are required to modify users.
BeforeImage Strikes Again… @josecgomez
This’ll do it.
try
{
this.CallService<Ice.Contracts.UserFileSvcContract>(uf =>
{
//Get the dataset
var dsUserFile = uf.GetByID(UserID);
//UnModified Record -> BeforeImage...
var userFile = dsUserFile.UserFile.FirstOrDefault();
//Get a new Record, this will be our updated Row
Ice.Tablesets.UserFileRow updatedUserFileRow = (Ice.Tablesets.UserFileRow)dsUserFile.UserFile.NewRow();
//Copy the unmodified row to the new row
BufferCopy.Copy(userFile, updatedUserFileRow);
//Modify the new row
updatedUserFileRow.UserDisabled = !enable;
updatedUserFileRow.RowMod = "U";
//Add it to the dataset
dsUserFile.UserFile.Add(updatedUserFileRow);
//Update
uf.Update(ref dsUserFile);
});
Success = true;
}
catch (Exception ex)
{
Success = false;
ErrorMessage = ex.Message;
}
{
“Success”: false,
“ErrorMsg”: “You are not allowed to modify other users unless you are a security manager.”,
“DebugMsg”: null
}
But I have already access of Security Manager.