Sunday, June 23, 2019

C# > add > Add a new employee with administrator access via web services.

If you would like to create a new employee via web services and give him the default administrator access below is a sample on how to do this.
Please note that a valid login session is required. 

*Warning: Ensure you do want this new employee to have Administrator access before implementing. The Administrator role has access to everything.

if (status.isSuccess == true)
{
// Creating an employee object with the required fields
Employee emp = new Employee();
emp.firstName = "First Name here";
emp.middleName = "Middle Name Here";
emp.lastName = "LastName Here";
emp.email = "fake@123.com";

// Giving the employee the Default Administrator Role (Internal ID: 3)
RecordRef role = new RecordRef();
role.internalId = "3";

// Creating the EmployeeRolesList Objects.
EmployeeRolesList roleList = new EmployeeRolesList();
EmployeeRoles[] roles1 = new EmployeeRoles[1];
EmployeeRoles roles = new EmployeeRoles();
roles1[0] = roles;
roleList.roles = roles1;
roles.selectedRole = role;

// Applying the roles to the employee object and giving the employee access to the account.
emp.rolesList = roleList;
emp.giveAccess = true;
emp.giveAccessSpecified = true;

// Giving the employee a temporary password.
emp.password = "abc123";
emp.password2 = "abc123";

// Sending in the add request for a new employee administrator.
WriteResponse res = nss.add(emp);

// Checking the status of the request.
if (res.status.isSuccess)
{
Console.WriteLine("Employee Successfully Added");
Console.Read();
}
else
{
Console.WriteLine("Employee Not Added");
Console.Read();
}

}

No comments:

Post a Comment