/// <summary> /// Links the Smartsheet user information to the Acumatica's Employee /// </summary> /// <param name="projectEntryGraph">Project graph</param> /// <param name="smartsheetClient">Smartsheet SDK Client</param> public void CreateEmployeesAcuUserSS(ProjectEntry projectEntryGraph, SmartsheetClient smartsheetClient) { User userRow = new User(); AccessUsers accessUsersGraph = PXGraph.CreateInstance <AccessUsers>(); AccessUsersSSIExt graphExtended = accessUsersGraph.GetExtension <AccessUsersSSIExt>(); try { EmployeeMaint employeeMaintGraph = PXGraph.CreateInstance <EmployeeMaint>(); foreach (EPEmployeeContract filter in projectEntryGraph.EmployeeContract.Select()) { EPEmployee ePEmployeeRecord = employeeMaintGraph.Employee.Current = employeeMaintGraph.Employee.Search <EPEmployee.bAccountID>(filter.EmployeeID); if (ePEmployeeRecord == null) { return; } EPEmployeeSSExt ePEmployeeExtRecord = PXCache <EPEmployee> .GetExtension <EPEmployeeSSExt>(ePEmployeeRecord); if (String.IsNullOrEmpty(Convert.ToString(ePEmployeeExtRecord.UsrSSUserid))) { userRow = graphExtended.CreateSmartsheetUser(filter.EmployeeID, smartsheetClient); if (userRow != null) { PXCache <EPUsersListSS> usersListCache = employeeMaintGraph.Caches <EPUsersListSS>(); EPUsersListSS epUsersListSSRow = UserSSList.Select().Where(x => ((EPUsersListSS)x).Ssuserid == userRow.Id).FirstOrDefault(); if (epUsersListSSRow == null) { EPUsersListSS usersListSSRow = (EPUsersListSS)usersListCache.Insert(new EPUsersListSS { Ssuserid = userRow.Id, FirstName = userRow.FirstName, LastName = userRow.LastName, Email = userRow.Email, BAccountID = filter.EmployeeID }); } else { epUsersListSSRow.BAccountID = filter.EmployeeID; epUsersListSSRow.FirstName = userRow.FirstName; epUsersListSSRow.LastName = userRow.LastName; epUsersListSSRow.Email = userRow.Email; usersListCache.Update(epUsersListSSRow); } employeeMaintGraph.Persist(); PXDatabase.Update <EPEmployee>(new PXDataFieldRestrict <EPEmployee.bAccountID>(filter.EmployeeID), new PXDataFieldAssign <EPEmployeeSSExt.usrSSUserID>(userRow.Id)); } } } } catch (Exception ex) { throw new PXException(ex.Message); } }
public new IEnumerable NewContact(PXAdapter adapter) { if (this.BAccountAccessor.Cache.GetStatus(this.BAccountAccessor.Current) != PXEntryStatus.Inserted) { EmployeeMaint graph = CreateInstance <EmployeeMaint>(); try { int?ParentBAccountID = BaccountIDForNewEmployee(); graph.Employee.Insert(new EPEmployee { RouteEmails = true, ParentBAccountID = ParentBAccountID }); graph.Employee.Cache.IsDirty = false; graph.Caches <RedirectEmployeeParameters>().Insert(new RedirectEmployeeParameters { RouteEmails = true, ParentBAccountID = ParentBAccountID }); } catch (PXFieldProcessingException ex) { if (graph.Employee.Cache.GetBqlField(ex.FieldName) == typeof(EPEmployee.parentBAccountID)) { throw new PXSetPropertyException(Messages.YouDoNotHaveSufficientAccessRightsToViewOrModifyAnEmployee, PXUIFieldAttribute.GetItemName(BAccount.Cache), BAccountAccessor.Current.AcctCD); } throw; } PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow); } return(adapter.Get()); }