Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Saturday, February 22, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: Get AccountID of logged on user in Customer Portal
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Apr 08 6:23 AM
Is there a function which will return the accountID or contactID of the logged on user in th customer portal? I need this to run some validation logic on a custom page. I tried to map the ID's to a hidden field, but they won't map. Some fields from the contact table will map, some won't. I could not get accountid, contactid, userfield1/2 or a custom field to map.
[Reply][Quote]
Nicolas Galler
Posts: 93
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Apr 08 10:41 AM
Once you have the UserService, you can do:

PortalUser user = ((WebPortalUserService)UserService).GetPortalUser();
IContact contact = user.Contact;
IAccount account = user.Contact.Account;

[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Apr 08 10:57 AM
Thanks Nicolas. Excuse my ignorance, but how do I get the UserService?
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 12:08 AM
From Jeffs FAQ (Where I have noticed many answers here originate):
http://www.sagesoftwareuniversity.com/crm/slxdeveloper.htm
(bottom of page 7)


Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get();

string currentUserId = userService.UserId;
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 7:10 AM
Thanks Jason. I've got the code you posted working, with one exception. The snip in the FAQ looks like this - some more code after 'services.Get' for anyone else who comes across this post:
Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string currentUserId = userService.UserId;

This returns 'ADMIN'.

When I add the code Nicolas posted I get:
The type or namespace name 'PortalUser' could not be found (are you missing a using directive or an assembly reference?)

I tried adding the following to the top of my smartpart in VS based on the faq (grasping at straws)..
<%@ Register Assembly="Sage.Platform.Application" Namespace="Sage.Platform.Application" TagPrefix="SalesLogix" %>
<%@ Register Assembly="Sage.Platform.Security" Namespace="Sage.Platform.Security" TagPrefix="SalesLogix" %>

Then I get the error:
Could not load file or assembly 'Sage.Platform.Security' or one of its dependencies. The system cannot find the file specified.

I think I a very close... what am I missing? Thanks
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 7:23 AM
Ok.. tried something different:
Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string currentUserId = userService.UserId;


Sage.SalesLogix.Web.WebPortalUserService user = (Sage.SalesLogix.Web.WebPortalUserService)userService;
Sage.SalesLogix.Security.PortalUser portalUser = user.GetPortalUser();
IContact objContact = portalUser.Contact;


This runs until the last line.. Now getting 'The type or namespace name 'IContact' could not be found (are you missing a using directive or an assembly reference?) '

What do I need to add? Thanks
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 11:10 AM
You need to start fully qualifying your namespaces

Sage.Entity.Interfaces.IContact objContact = portalUser.Contact;

Or include Sage.Entity.Interfaces at the top..

Good job!
I dont see what code you refer to "after the Get():" in my post though?
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 11:44 AM
Doh! I think the forum tried to render the bit after Get(); as HTML - without the greater than less than tags this was what worked Get Sage.Platform.Security.IUserService ();

Ok, I feel like I am coding with training wheels on but on the edge of enlightenment.

I now have the code working to here, but don't know how to get my accountID.. Just trying to get the account name below:


Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string currentUserId = userService.UserId;

Sage.SalesLogix.Web.WebPortalUserService user = (Sage.SalesLogix.Web.WebPortalUserService)userService;
Sage.SalesLogix.Security.PortalUser portalUser = user.GetPortalUser();
Sage.Entity.Interfaces.IContact objContact = portalUser.Contact;

Fails here>>> string sAccount = objContact.Account.;
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 11:50 AM
You know what is wrong

objContact.Account is an object of type IAccount.... not a string.

So you might be able to do
string sAccountName = objContact.Account.AccountName;
or
Sage.Entity.Interfaces.iAccount objAccount = objContact.Account;
string sAccountName = objAccount.AccountName;


But doesnt the portaluser have an account on it?

so you could do

string sAccountName = portalUser.Account.AccountName;
perhaps?

(I am not testing this but through you, so give it a try
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 12:14 PM
Yeah, I know what's wrong.. operater error. lol

This worked for account name,
string sAccountName = objContact.Account.AccountName;

but when I try to get accountID I get this:
string sAccountName = objContact.Account.AccountID;
'Sage.Entity.Interfaces.IAccount' does not contain a definition for 'AccountID'

This failed also:
Sage.Entity.Interfaces.iAccount objAccount = objContact.Account;
string sAccountName = objAccount.AccountID;

The type or namespace name 'iAccount' does not exist in the namespace 'Sage.Entity.Interfaces' (are you missing an assembly reference?)

This also failed although I did not capture the error:
string sAccountName = portalUser.Account.AccountName;
- something about AccountName not being a member of portalUser or something..
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 1:00 PM
Alright, it seems like AccountID is locked out.. Can't map to a textfield, although accountname will show up.

This works:
Sage.Entity.Interfaces.IAccount objAccount = objContact.Account;
string sAccountName = objAccount.AccountName;

This does not:
Sage.Entity.Interfaces.IAccount objAccount = objContact.Account;
string sAccountID = objAccount.AccountID;

Is this some kind of security restriction? Tech support said it shouldn't be but couldn't offer much more..
[Reply][Quote]
Jason Huber
Posts: 77
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 1:19 PM
Its Id not ID. sorry.

string sAccountID = objAccount.AccountId;

Typo on my part....
You can tell by expanding the account entity and then properties FYI
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 2:03 PM
Stilll getting the error:
'Sage.Entity.Interfaces.IAccount' does not contain a definition for 'AccountId'

[Reply][Quote]
Jason Huber
Posts: 77
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Apr 08 2:52 PM
Sorry looked using reflector. I dont see it there.
I looked at Portal User as well.
It has a contact property, but no account.

So... if you go into AA and double-click the account entity you can then choose to include AccountId in the generated entity..

Then you will have it as Account.AccountId (I cant find the cross my fingers keystroke, but I checked reflector and it shows it after the above step)

I'll be adding this as a how to in the Dev Subscription --> Good one.
[Reply][Quote]
Steve Knowles
Posts: 657
Top 10 forum poster: 657 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Apr 08 9:20 AM
Got it. Always an adventure with 7.2 web.. I'll follow up with tech support so they can help the next guy. The answer is so often a checkbox away.. Thanks Jason, I appreciate the help.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 05 Apr 08 1:38 PM
Hi Steve,

Could have saved you some time, I already had that posted here: http://saleslogixblog.com/rfarley/archive/2007/12/10/38661.aspx

Anyway, on the AccountID thing, all entities inherit from EntityBase which as a built in object property named "Id" that will return the entity's primary ID value. You *don't* want to check the Include box on the Account for the AccountId property, just use the built in Id property. The AccountId property is intentionally unchecked - you won't break anything by checking it, just that you'll have redundant properties on the entity.

So you'd use:

string accountid = objContact.Account.Id.ToString();

Again, note that the Id property is an object property - you'll need to convert to a string.

-Ryan
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Get AccountID of logged on user in Customer PortalYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 08 Apr 08 7:12 AM
To expand on what Ryan is saying. If you look at the entities the IDs are generally never included. Instead the relationships provide the Ids through the child entities and the included Id property. If you have a relationship and include the table id in the entity when you try to commit a change you would get a SQL error saying something like duplicate column names included where there would be to AccountID columns in the sql.

Mark
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 2/22/2025 4:11:44 PM