It’s easy to access the UserService interface from a Code Snippet Action item in the SalesLogix web client. For this example, I’m just going to add a button on account detail which will launch a DialogService message with the current user.
After adding the button to the AccountDetails form, I added a new CodeSnippet action item to the onclick event of the button, creating it as a C# Code snippet.
Since we’re using a code snippet action item, we’ll need to actually get the IUserService with the following code:
Sage.Platform.Security.IUSerService user = form.Services.Get<Sage.Platform.Security.IUserService>;
That’s really all you need to do to access the IUserService. Once we have that, we have access to the CurrentUserID, if we wanted to do something with that in code. Since I’m displaying this in a Dialog, we’ll need to get the IWebDialogService to be able to call the dialog:
Sage.Platform.WebPortal.Services.IWebDialogService dlg = form.WorkITem.Services.Get<Sage.PLatform.WebPortal.Services.IWebDialogService>();
Once that is done, calling the dialog itself is a simple matter of calling the dialog’s ShowMessage function:
dlg.ShowMessage(“Current User: ” + user.PrettyName);
That’s all there is to it! Again, we also have access to the current user’s ID if we wanted to use that for some purpose. In future articles, I’ll give some more examples of what we can do with the UserService interface.