Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Silver Contributor
Posts: 835
Registered: ‎03-24-2009
Accepted Solution

Userinfo.Division

In 7.5.4 Web, what's the easiest/fastest way to get the current user's division? I didn't see it in user services/security and am currently getting it via OLE DB (SQL).

 

Thanks!

RJ Samp
Nickel Contributor
Posts: 59
Registered: ‎07-30-2010

Re: Userinfo.Division

The below should work - You might need to add on Sage.SalesLogix.Security to some, depending on where you are placing the code.

SLXUserService service = ApplicationContext.Current.Services.Get<IUserService>() as SLXUserService;
if (service != null)
{
IUser user = service.GetUser();
string div = user.UserInfo.Division
}


Thanks,
Richard Anderson
CRM Consultant
K3 CRM
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Userinfo.Division

I get an error using that, this is specifically in 7.5.4.

 

    // 7.5.2 or before:
// Sage.SalesLogix.Security.SLXUserService usersvc = (Sage.SalesLogix.Security.SLXUserService)Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
// Sage.SalesLogix.Security.User user = usersvc.GetUser();


    //7.5.3 or higher (avoids an implicit cast).
// Sage.SalesLogix.Security.SLXUserService usersvc = (Sage.SalesLogix.Security.SLXUserService)Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
// Sage.SalesLogix.Security.User user = usersvc.GetUser() as Sage.SalesLogix.Security.User;
   
// now get the user's Division (doesn't work, not a Security object?)
// Sage.SalesLogix.Security.Division division = user.Division;   
// string userdivision = division.UserInfo.Division;

 

It may be a variant of this:

Sage.SalesLogix.Security.Division division = user.Division;   
string userdivision = division.UserInfo.Division;

 

 

RJ Samp
Nickel Contributor
Posts: 59
Registered: ‎07-30-2010

Re: Userinfo.Division

Hello,

I use the code snippet above in a DLL and it works just fine on 7.5.4, not sure what you have to do to get this to work if using direct from a Quick form.

Division is part of IUserInfo.

What errors are you getting, and where/how are you placing the code?

Thanks,
Richard Anderson
Richard Anderson
CRM Consultant
K3 CRM
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Userinfo.Division

I put this in an ascx.cs form and added the reference to Sage.SalesLogix.Security and it works perfectly!

 

THANKS!!!

RJ Samp
Highlighted
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Userinfo.Division

OK, I need a workaround.....Insert Opportunity blows up on the IUser call....

 

\SlxClient\SmartParts\Opportunity\InsertOpportunity.ascx(516): error CS0246: The type or namespace name 'IUser' could not be found (are you missing a using directive or an assembly reference?)

RJ Samp
Nickel Contributor
Posts: 59
Registered: ‎07-30-2010

Re: Userinfo.Division

[ Edited ]

Use Sage.Entities.Interfaces.IUser instead

 

Thanks,

Richard Anderson
CRM Consultant
K3 CRM
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Userinfo.Division

I need this to run in an event......it's not picking up either of the calls.....

 

        public static void OnBeforeInsertStep( IHistory history,  ISession session)
        {
            // TODO: Complete business rule implementation
            if (history.ProductLine == null || history.ProductLine.Length < 1)
                (
                    // set the Product Line to the current user's Division.
                    /// Sage.Entity.Interfaces.IUser user = Sage.SalesLogix.API.MySlx.Security.CurrentSalesLogixUser;
                    SLXUserService service = ApplicationContext.Current.Services.Get<IUserService>() as SLXUserService;
                    if (service != null)
                    {
                        IUser user = service.GetUser();
                        //set the product line to the current user's division.
                        history.ProductLine  = user.UserInfo.Division;
                    }
        }    
        }

RJ Samp
Silver Contributor
Posts: 835
Registered: ‎03-24-2009

Re: Userinfo.Division

Helps to use { instead of ( after an if statement......

RJ Samp