protected virtual void EPEmployee_UsrSSUserID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { if (e.Row == null) { return; } EPEmployee epEmployeeRow = (EPEmployee)e.Row; EPEmployeeSSExt epEmployeeExtRow = PXCache <EPEmployee> .GetExtension <EPEmployeeSSExt>(epEmployeeRow); if ((long?)e.OldValue != epEmployeeExtRow.UsrSSUserid) { PXCache <EPUsersListSS> usersListCache = this.Base.Caches <EPUsersListSS>(); EPUsersListSS epUsersListSSRow = UserList.Select().Where(x => ((EPUsersListSS)x).Ssuserid == (long?)e.OldValue).FirstOrDefault(); if (epUsersListSSRow != null) { epUsersListSSRow.BAccountID = null; usersListCache.Update(epUsersListSSRow); } if (epEmployeeExtRow.UsrSSUserid != null) { epUsersListSSRow = UserList.Select().Where(x => ((EPUsersListSS)x).Ssuserid == epEmployeeExtRow.UsrSSUserid).FirstOrDefault(); if (epUsersListSSRow != null) { epUsersListSSRow.BAccountID = epEmployeeRow.BAccountID; usersListCache.Update(epUsersListSSRow); } } } }
/// <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); } }