I want programatically in C# to assign the current user ID to a combo box but it doesn’t work. I don,t have any error, just that my field is empty. What’s the proper way to do so?
I have this code:
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
Ice.Core.Session ss=(Ice.Core.Session)MainController.Session;
string currentUserID = ss.UserID.ToUpper();
string currentUserName = ss.UserName;
EpiCombo _comboProjectManager = (EpiCombo)csm.GetNativeControlReference("8b0c1ffa-ea70-4224-b958-48d37ec17f87");
_comboProjectManager.Value = currentUserID;
_comboProjectManager.Text = currentUserName;
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
oTrans.BeforeAppControllerEvent += oTrans_BeforeAppControllerEvent;
// End Wizard Added Custom Method Calls
}
Yes, sorry for the lack of explanation. It’s a dashboard with a filter section at the top in a view. There are input so if I put my userID in ‘Project Manager’, I want the bottom view (table) to display my projects.
Sorry, I got a better idea finally. I don’t need the combo box to have the value, I just need to show the lines of my table which has [‘ConProjMng’] = Session.UserID . How could I do that ?
I’ll change the filters after that manually to show different projects but it would be perfect that way.
I have the same BAQ already but I also have a security group that, if the user is a member, will show all projects. I’ve attached the BAQ but also displaying the SQL statement below.
Mark W.
select
[Project].[ProjectID] as [Project_ProjectID],
[Project].[Description] as [Project_Description],
[EmpBasic].[Name] as [EmpBasic_Name],
((case when [Ice].lookup('101-ProjectAdmin', UserFile.GroupList, '~') > 0 then 'Y' else 'N' end)) as [Calculated_InGroup]
from Erp.Project as Project
left outer join Erp.EmpBasic as EmpBasic on
Project.Company = EmpBasic.Company
and Project.ConProjMgr = EmpBasic.EmpID
inner join Erp.UserFile as UserFile on
Project.Company = UserFile.CurComp
and ( UserFile.DcdUserID = @CurrentUserID )
inner join Erp.EmpBasic as EmpBasic1 on
UserFile.DcdUserID = EmpBasic1.DcdUserID
inner join (select
[ProjPhase1].[Company] as [ProjPhase1_Company],
[ProjPhase1].[ProjectID] as [ProjPhase1_ProjectID]
from Erp.ProjPhase as ProjPhase1
where (ProjPhase1.PhaseStatus <> 'C')
group by [ProjPhase1].[Company],
[ProjPhase1].[ProjectID]) as OpenPhases on
Project.Company = OpenPhases.ProjPhase1_Company
and Project.ProjectID = OpenPhases.ProjPhase1_ProjectID
where (Project.ProjectType_c = 'CUST' or Project.ProjectType_c = 'IC')
and (Project.ConProjMgr = EmpBasic1.EmpID or ((case when [Ice].lookup('101-ProjectAdmin', UserFile.GroupList, '~') > 0 then 'Y' else 'N' end)) = 'Y' )
order by EmpBasic.Name, Project.ProjectID
```<a class="attachment" href="/uploads/default/original/2X/5/540cabe5e0bd8ff43244128d0258326616203a1b.baq">101-MgrProjects.baq</a> (32.5 KB)
Thanks for the code, would work in the same situation but I forgot to add that I have 2 or 3 other fields that needs to be compared (project manager or automation manager or sales manager, etc.) so I would need to do it in a custo instead since every user can look at anyone’s project list.
Ideally, if I can just filter the rows by opening the form to show the projects of the current user but if he refresh with the filters at the top, it will show the projects based on the filters.
[quote=“Stevensi1018, post:4, topic:49917”] …
I just need to show the lines of my table which has [‘ConProjMng’] = Session.UserID …
[/quote]
I just had a similar situation where I needed to get the current UserID to assign it to a UD (char) field. I used this code to get the Session data into 'userSess" then called it when setting the ID to a ShortChar field later in the code.
Ice.Core.Session userSess = (Ice.Core.Session)SalesOrderForm.Session; // Get Session for UserID
...
Row["UDField_c"] = userSess.UserID.ToString();
@Mark_Wonsil, the Ice.lookup() is interesting. Do you know if there is a way to pass more than 1 group/string, say I want to filter if the user belongs to one of a list of Groups instead of just one?
I think Lookup is string to string. If you wanted a to look into more than one like, you could loop through an array of strings calling Lookup. If that’s what you mean. If you meant an entry in each group then I would do what Calvin suggested.
Thanks Calvin, that’s what I’m going with, but since I didn’t understand the Ice.Lookup() Function (?) I didn’t know what types of arguments could be passed nor what data (or data type) was returned so I thought I’d ask. I didn’t know if it was Epicor’s version of one of the other Lookup functions. If I have a bit of time today, I’m gonna poke at this function a bit and see if I can work out its capabilities.
Ok, so I found the details to this function.
It is an SQL Function Epicor created, all parameters are required:
[Ice].[lookup](nvarchar(1000), nvarchar(max), nchar(1))
[Ice].[lookup]([string to lookup], [table.field to search], [delimiter])
returns number of matches as int
The string match is an equals operator.
Only works if you have a delimited string you need to search.
It’s a nice, easy shortcut to an otherwise involved alternatives such as a subquery.
I wish the function definition in the calculated fields function list was a bit more precise in how to use the function.
lookup(string to find, string to search, [delimiter])
entry(integer item, string, [delimeter]) - returns the (1-based array) string item within the string
num-entries(string, [delimeter]) - returns an integer of the number of items
All are recreations of functions used in the Progress Era and are available within BAQs. Delimiter is the comma if not provided.
After looking at this function some more, I have further questions/concerns…
At first, it just looks like something that splits a delimited string into an array, and then returns the index of the element (plus one) that matches the search string.
But [table.field to search] isn’t a string. It is a column of a table.
So which row/record of the referenced table is used?
For example, if my UserFile table was the following:
UserID GroupList
alice SysAdmin~ProjectAdmin~LilDevil
bob ProjectAdmin~LilDevil
charlie LilDevil~Production
donna LilDevil~SaleMkgt