Unable to create new user using Epicor Function

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

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.

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

Check your server log

2 Likes

Wrap the code in a try catch and dump the exception to an output variable.

It’s probably an existing userid.

1 Like

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

We have to call in the external dll.

3 Likes

Here @Hari_Dutt

Dropped in a function:

HariDutt.efxb (1.9 KB)

image

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

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.

Are you using the same user in your “external dll”. Does that service user have security manager permission?

2 Likes

Meanwhile I am calling this function through Rest API in Swagger UI. Yes, I have the security manager access.

1 Like

Go see if you can make one in user account security maintenance.

Yes, I am able to create a new user using user account security maintenance.

Logged in as the same exact user ?

1 Like

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?

@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 :slight_smile:

3 Likes

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