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!
|
|
Get AccountID of logged on user in Customer Portal
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. |
|
|
| |
| |
| |
|
Re: Get AccountID of logged on user in Customer Portal
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
|
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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 |
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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? |
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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.; |
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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  |
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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.. |
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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.. |
|
|
| |
| |
|
Re: Get AccountID of logged on user in Customer Portal
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. |
|
|
| |
|
Re: Get AccountID of logged on user in Customer Portal
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
|
|
|
|
Re: Get AccountID of logged on user in Customer Portal
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 |
|
|
|