I have created a Epicor Function and trying to create a new user using below code but unbale to create a new user
this.CallService<Erp.Contracts.UserFileSvcContract>(UserFilesvc =>
{
UserFileTableset ds = new UserFileTableset();
UserFilesvc.GetNewUserFile(ref ds);
ds.UserFile[0].UserID ="Test";
ds.UserFile[0].Name = "Test";
ds.UserFile[0].Address1 = "India";
UserFilesvc.Update(ref ds);
}) ;
Similar code is working in BPM. Anyone can suggest how we can resolve this issue in Epicor Function Maintenance.
Thanks in advance.
1 Like
mbayley
(Michael Bayley)
July 4, 2024, 2:17pm
2
I don’t see where UserFilesvc
is defined. Try replacing with svcUF
within your lambda?
It’s a typo mistake. But it is not working. I have corrected the expression.
klincecum
(Kevin Lincecum)
July 4, 2024, 2:33pm
4
Use Ice.UserFile
→ Link Thanks @Chris_Conn
<tracePacket>
<businessObject>Ice.Proxy.BO.UserFileImpl</businessObject>
<methodName>GetNewUserFile</methodName>
<tracePacket>
<businessObject>Ice.Proxy.BO.UserFileImpl</businessObject>
<methodName>Update</methodName>
Otherwise you will get errors about payroll manager priviledges.
As well as you had the errors @mbayley said. You weren’t referencing svcUF
.
CallService<Ice.Contracts.UserFileSvcContract>(svcUF =>
{
Ice.Tablesets.UserFileTableset ds = new Ice.Tablesets.UserFileTableset();
svcUF.GetNewUserFile(ref ds);
ds.UserFile[0].UserID = "Test";
ds.UserFile[0].Name = "Test";
ds.UserFile[0].Address1 = "India";
svcUF.Update(ref ds);
});
2 Likes
Getting below mentioned error while calling above function through Rest API
Sorry! Something went wrong. Please contact your system administrator. Correlation Id: 7272b9c6-2cdc-4085-b0d6-d085387728c6
klincecum
(Kevin Lincecum)
July 4, 2024, 7:47pm
7
Wrap the code in a try catch and dump the exception to an output variable.
It’s probably an existing userid.
1 Like
Hally
(Simon Hall)
July 4, 2024, 11:43pm
8
What’s the purpose of doing this? Are you trying to create some sort of tool?
Just a reminder you can add users through the Admin console, as well as copying an existing user’s security.
2 Likes
Hari_Dutt
(Hari Dutt)
July 5, 2024, 12:49pm
9
We have to call in the external dll.
3 Likes
klincecum
(Kevin Lincecum)
July 5, 2024, 4:21pm
10
Here @Hari_Dutt
Dropped in a function:
HariDutt.efxb (1.9 KB)
try
{
CallService<Ice.Contracts.UserFileSvcContract>(svcUF =>
{
Ice.Tablesets.UserFileTableset ds = new Ice.Tablesets.UserFileTableset();
svcUF.GetNewUserFile(ref ds);
var newUser = ds.UserFile.FirstOrDefault();
newUser.UserID = UserID;
newUser.Name = Name;
newUser.Address1 = Address;
svcUF.Update(ref ds);
DebugMsg = ds.UserFile.FirstOrDefault().Name;
});
Success = true;
}
catch (Exception ex)
{
Success = false;
ErrorMsg = ex.Message;
}
Payload:
{
"UserID": "Test3",
"Name": "Test3",
"Address": "1235 Butt Street"
}
Output:
//Submit first pass
{
"Success": true,
"ErrorMsg": null,
"DebugMsg": "Test3"
}
//Submit second pass (duplicate / error)
{
"Success": false,
"ErrorMsg": "This is a duplicate entry of an existing record.",
"DebugMsg": null
}
2 Likes
Hari_Dutt
(Hari Dutt)
July 5, 2024, 5:21pm
11
Thanks for support. I have tried this code and getting below error
{
“Success”: false,
“ErrorMsg”: “You are not allowed to modify other users unless you are a security manager.”,
“DebugMsg”: null
}
I have checked in User Account maintenance and Security Manger access is already true.
mbayley
(Michael Bayley)
July 5, 2024, 5:26pm
12
Are you using the same user in your “external dll”. Does that service user have security manager permission?
2 Likes
Hari_Dutt
(Hari Dutt)
July 5, 2024, 5:31pm
13
Meanwhile I am calling this function through Rest API in Swagger UI. Yes, I have the security manager access.
1 Like
klincecum
(Kevin Lincecum)
July 5, 2024, 5:37pm
14
Go see if you can make one in user account security maintenance.
Hari_Dutt
(Hari Dutt)
July 5, 2024, 6:01pm
15
Yes, I am able to create a new user using user account security maintenance.
klincecum
(Kevin Lincecum)
July 5, 2024, 6:03pm
16
Logged in as the same exact user ?
1 Like
Hari_Dutt
(Hari Dutt)
July 26, 2024, 2:22pm
17
I am trying to add multiple companies access to new user but getting below
“User Account must have access to at least one plant for each authorized company.”,
Code:
try
{
CallService<Ice.Contracts.UserFileSvcContract>(svcUF =>
{
Ice.Tablesets.UserFileTableset ds = new Ice.Tablesets.UserFileTableset();
svcUF.GetNewUserFile(ref ds);
var newUser = ds.UserFile.FirstOrDefault();
newUser.UserID = UserID;
newUser.CurComp = CurComp;
//newUser. = CompList;
newUser.Name = Name;
newUser.Address1 = Address;
newUser.PasswordBlank = true;
newUser.City = City ;
newUser.State = State ;
newUser.Country= "India";
newUser.ExternalIdentity = Email;
newUser.CanPersonalize = true;
svcUF.Update(ref ds);
string[] Companies = CompList.Split('~');
for(int i = 0; i < Companies.Length; i++)
{
svcUF.AddUserCompany(UserID, ref ds);
var newComp = ds.UserComp.FirstOrDefault();
newComp.Company = Companies[i].Trim();
newComp.EmpID = EmpID ;
newComp.WorkstationID = WorkstationID;
newComp.CurPlant = Site;
newComp.PlantList = Site;
svcUF.Update(ref ds);
}
DebugMsg = ds.UserFile.FirstOrDefault().Name;
//DebugMsg = ds.UserFile[0].Name;
});
Success = true;
}
catch (Exception ex)
{
Success = false;
ErrorMsg = ex.Message;
}
anyone can suggest?
CSmith
(Clint Smith)
July 26, 2024, 3:23pm
18
@Hari_Dutt could you please review this post (Code Syntax Highlighting in Posts ) and edit yours for better readability to help others assist you better
3 Likes
Hari_Dutt:
newComp.CurPlant
I was able to get it to work - I had to set curComp before adding companies and plants. My example uses 1 company and 1 plant but it did create the user and assign them to 2 user security groups.
The only part I am still working on is having it send the email out.
It creates the user with a blank password even though I tell it to not blank the password.
string company = callContextClient.CurrentCompany;
string plant = callContextClient.CurrentPlant;
try
{
CallService<Ice.Contracts.UserFileSvcContract>(svcUF =>
{
Ice.Tablesets.UserFileTableset ds = new Ice.Tablesets.UserFileTableset();
svcUF.GetNewUserFile(ref ds);
string userID = "Test123";
ds.UserFile[0].UserID = userID;
ds.UserFile[0].Name = "Test124";
ds.UserFile[0].Address1 = "Greenland";
ds.UserFile[0].PwdExpiresDays = 0;
ds.UserFile[0].PasswordBlank = false;
ds.UserFile[0].PasswordEmail = "testemail@someddomain.com";
ds.UserFile[0].UserDisabled = false;
ds.UserFile[0].GroupList = "ITSpec~ITMgr";
ds.UserFile[0].CurComp = company; // If not set you will get an error
// Do the following for each company that you wish to add the user to - up until you set the plant. The following 4 lines can be in a loop
svcUF.AddUserCompany(userID, ref ds);
var newComp = ds.UserComp.FirstOrDefault();
newComp.Company = company;
newComp.CurPlant = plant;
svcUF.Update(ref ds);
});
}
catch(Exception e)
{
throw new Exception(company + " " + plant + " " + e.Message);
}
2 Likes