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!
|
|
New to Web Development
Posted: 20 Apr 09 2:59 PM
|
I need to default the Account Manager (User selection) to the Current User on the Insert Opportunity Form. Currently it defaults to the Account Manager of the Account selected.
I am able to get the Current UserID out, but I cant figure out how to put it back into the form.
I have tried the following with no luck. I am sure I am just missing something simple. I used a "ShowMessage" right before each line to make sure I am getting the correct CurrentUserID and it shows up correctly, so I know the code is running.
form.usrUser.text = currentUserId.ToString(); <-- Does nothing form.usrUser = currentUserId.ToString(); <-- "cannot be assigned to -- it is read only" Error on build form.usrUser.LookupResultValue = currentUserId.ToString(); <-- Does nothing
Thanks
|
|
|
|
Re: New to Web Development
Posted: 20 Apr 09 5:56 PM
|
How are you getting the current userid? If you're using the UserService then you can also get the current user object from that.
Sage.Platform.Security.IUserService userService = form.WorkItem.Services.Get<Sage.Platform.Security.IUserService>(); form.usrUser.LookupResultValue = userService.GetUser();
Make sense? |
|
|
|
Re: New to Web Development
Posted: 21 Apr 09 5:30 AM
|
Originally posted by Ronnie Martin
I need to default the Account Manager (User selection) to the Current User on the Insert Opportunity Form. Currently it defaults to the Account Manager of the Account selected.
I am able to get the Current UserID out, but I cant figure out how to put it back into the form.
I have tried the following with no luck. I am sure I am just missing something simple. I used a "ShowMessage" right before each line to make sure I am getting the correct CurrentUserID and it shows up correctly, so I know the code is running.
form.usrUser.text = currentUserId.ToString(); <-- Does nothing form.usrUser = currentUserId.ToString(); <-- "cannot be assigned to -- it is read only" Error on build form.usrUser.LookupResultValue = currentUserId.ToString(); <-- Does nothing
Thanks
|
|
I would set the AccountManager at the Entity level, not the form level, something like:
//Sage.Platform.Security.IUserService userService = form.WorkItem.Services.Get(); //opp.AccountManager = (Sage.Entity.Interfaces.IUser)userService;
The form would then obviously reflect what is on the entity, so it would reflect the correct value.
As an aside, your code wouldnt work as you need to set the LookupResultsValue of the lookup - this LookupResultsValue is an "object (IUser)" so needs to be a User object (see Ryan's response above), not a string value. |
|
|
|
Re: New to Web Development
Posted: 21 Apr 09 9:25 AM
|
Thanks for the help! I am going to work on it againt today and see if I can get it work.
I am using the following to get the UserID.
//Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
//string currentUserId = userService.UserId;
|
|
|
|
Re: New to Web Development
Posted: 21 Apr 09 10:04 AM
|
What Nick says is spot on - if it makes sense to do it in the entity's OnCreate event then that is a better place to do it than on the form.
However, also mentioned that the LookupResultValue is expecting an object, not a string. Instead of using this:
mylookup.LookupResultValue = userService.UserId;
use this:
mylookup.LookupResultValue = userService.GetUser();
-Ryan |
|
|
|
Re: New to Web Development
Posted: 24 Apr 09 4:55 PM
|
Originally posted by Ryan Farley
mylookup.LookupResultValue = userService.GetUser();
|
|
When I did that i got the error below when I clicked 'Build Web Platform'.
'Sage.Platform.Security.IUserService' does not contain a definition for 'GetUser'
So I tried it with "mylookup.LookupResultValue = userService.GetType();", and I didn't get a build error, but nothing happened on the Insert Opportunity Screen. I am going try the way Nick suggested. I will let you know.
Thanks |
|
|
|
Re: New to Web Development
Posted: 07 May 09 2:51 PM
|
Ryan, Do you know why the .GetUser() is not an option for my userService object?
Do I need to include some other file in my using area? I tried to use .GetType() but that doesn’t seem to return what I need.
I've seen other documentation using the .GetUser() but it’s not working for me.
Any advice would be much appreciated!
Thanks, Ronnie |
|
|
|
Re: New to Web Development
Posted: 07 May 09 3:17 PM
|
What type of Object is your user Service object? It has to be an SLXUserService (or Derived object).
Try: Sage.SalesLogix.Security.SLXUserService slxUserService = ApplicationContext.Current.Services.Get() as Sage.SalesLogix.Security.SLXUserService; slxUserService.GetUser().Id.ToString(); |
|
|
|
Re: New to Web Development
Posted: 07 May 09 3:34 PM
|
My UserService Object is defined in the following.
Sage.Platform.Security.IUserService userService = form.WorkItem.Services.Get();
I tired the code you posted, but I was unable to get it to work. I changed SalesLogix to Platform and SLXUserService to IUserService, but then I am back to where I started. |
|
|
|
Re: New to Web Development
Posted: 08 May 09 6:10 AM
|
Ronnie, looking at the provided code snippets as well as yours it seems that there is a bit of secret sauce missing. It is correct to get the IUserService implemented object from the service collection but you have to specify what object to get from the service collection. Using form.WorkItem.Services.Get() would not work as the type is not specified. Use the following code;
Sage.SalesLogix.Security.SLXUserService userService = ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>() as Sage.SalesLogix.Security.SLXUserService;
Sage.SalesLogix.Security.User user = userService.GetUser();
BTW, ryans code is correct
Mark |
|
|
|
Re: New to Web Development
Posted: 28 Aug 09 7:06 PM
|
This new web code is SOOOO much cleaner than the old vbscript and Application Object...
So to equate this to old code:
Sage.SalesLogix.Security.SLXUserService userService = ApplicationContext.Current.Services.Get() as Sage.SalesLogix.Security.SLXUserService;
Sage.SalesLogix.Security.User user = userService.GetUser();
is the counterpart to userid = Application.BasicFunctions.CurrentUserID
Way to go Sage! |
|
|
|
Re: New to Web Development
Posted: 28 Aug 09 9:54 PM
|
Yes, but to be fair the call in web returns more then just the Id. Also it iis quite easy to wrap this stuff up in a easier manner and Sage is aware and I expect they will be doing something to make accessing this kind of functionality easier in the future.
Mark |
|
|
|
Re: New to Web Development
Posted: 29 Aug 09 6:11 PM
|
Yes, wrapping this stuff up into convenient and concise code is an ongoing project. |
|
|
|
Re: New to Web Development
Posted: 30 Aug 09 12:26 PM
|
Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get(); string currentUserId = userService.UserId;
|
|
|
|
Re: New to Web Development
Posted: 06 Oct 10 8:58 AM
|
Hello,
I trying also to change the default account manager to current user on insert opportunity. This code can change the lookup:
Sage.SalesLogix.Security.SLXUserService us = (Sage.SalesLogix.Security.SLXUserService) Sage.Platform.Application.ApplicationContext.Current.Services.Get(); string uid = us.UserId + "";
this.usrUser.LookupResultValue = uid; this.usrUser.Text = us.UserName;
But when I save the opportunity, the account manager is the account manager from Account, not the current user.
what's wrong ?
Thanks
BEN |
|
|
| |
|
Re: New to Web Development
Posted: 26 Mar 15 11:01 AM
|
Just to help out anyone else that stumbles across this post, like I did, trying to achieve the same thing, the following worked for me (Infor CRM Web 8.1) after reading the posts above.
In a new Form Load Action (C# Snippet Action) on the Insert Opportunity form you can use the following code to default the account manager to the current user (this is editable before saving).
//Default the opportunity account manager to the current logged in user
Sage.Entity.Interfaces.IOpportunity opportunity = BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;
Sage.Platform.Security.IUserService userService = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
Sage.Entity.Interfaces.IUser user = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IUser>(userService.UserId);
opportunity.AccountManager = user; |
|
|
| |
|