Limit add record authorization to super users

Jaime Lazaro

**** Purpose of the customize rule ****

The following customize optimizer rule limits add record authorization in the master item data form to super users.
****Requirements for this customize rule ****

The rule requires coresuite Version 3.40 or higher and SAP Business One 8.8 or higher.
**** Procedure to use the customize rule ****

1. Download the attached *.cocu file

2. Import in SAP Business One: view > Administration > Add-Ons > coresuite customize > Import / Export > Import rules. In the message box, select “All Active”. Click on “Import”.

3. Open form Item Master Data, using a non-super user account.

4. Try to enter a new record. You should get the following error message:

[center][sharedmedia=core:attachments:205][/center]

try

{

// **************** Parameter **********************************
string UserID = Convert.ToString(SwissAddonFramework.B1Connector.GetB1Connector().UserId);
// **************** Logic **************************************

// Get the information if the current user us a Sales Person and not a super user

System.Data.SqlClient.SqlCommand sqlUSR = new System.Data.SqlClient.SqlCommand();

sqlUSR.CommandText = "SELECT User_Code, SuperUser FROM OUSR WHERE userID = @userID";

sqlUSR.Parameters.AddWithValue("@userID", UserID);

using(System.Data.SqlClient.SqlDataReader sdr = SwissAddonFramework.B1Connector.GetB1Connector().ExecuteQuery(sqlUSR))

{

if(sdr.Read())

{

// If the current user is a not a SuperUser the user is not allowed to add an item)

if((sdr["SuperUser"].ToString() == "N"))

{

string msg = "You do not have permission to add new items.";

StatusBar.WriteError(msg);

MessageBox.Show(msg, "OK");

return false;

}

}

}

}

// **************** Exception Handling **************************

catch(System.Exception ex)

{

string message = "Unexpected error in customize rule: " + ex;

Debug.WriteMessage(message, SwissAddonFramework.Messaging.Debug.DebugLevel.Exception);

StatusBar.WriteError(message);

MessageBox.Show(message, "OK");

}

return true;

0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post