private void CreateActivity(int classId, Guid?refNoteID, string typeCode, Guid?owner, PXRedirectHelper.WindowMode windowMode = PXRedirectHelper.WindowMode.NewWindow) { var graphType = CRActivityPrimaryGraphAttribute.GetGraphType(classId); if (!PXAccess.VerifyRights(graphType)) { throw new AccessViolationException(CR.Messages.FormNoAccessRightsMessage(graphType)); } CRActivity activity = null; var cache = CreateInstanceCache <CRActivity>(graphType); if (cache == null) { return; } if (owner == null) { owner = EmployeeMaint.GetCurrentEmployeeID(cache.Graph); } Action <object> initializeHandler = delegate(object act1) { var act = act1 as CRActivity; if (act == null) { return; } act.ClassID = classId; act.RefNoteID = refNoteID; if (!string.IsNullOrEmpty(typeCode)) { act.Type = typeCode; } act.OwnerID = owner; }; EntityHelper helper = new EntityHelper(cache.Graph); var type = helper.GetEntityRowType(refNoteID); var entity = helper.GetEntityRow(type, refNoteID); Type entityGraphType = null; if (type != null) { PXPrimaryGraphAttribute.FindPrimaryGraph(cache.Graph.Caches[type], ref entity, out entityGraphType); } if (entityGraphType != null) { PXGraph entry = PXGraph.CreateInstance(entityGraphType); PXCache <CRActivity> activityCache = entry.Caches[typeof(CRActivity)] as PXCache <CRActivity>; if (activityCache != null) { entry.Views[entry.PrimaryView].Cache.Current = entity; activity = (CRActivity)activityCache.CreateInstance(); if (initializeHandler != null) { initializeHandler(activity); } activity = activityCache.InitNewRow(activity); } } if (activity == null) { activity = (CRActivity)cache.CreateInstance(); initializeHandler(activity); activity = ((PXCache <CRActivity>)cache).InitNewRow(activity); } cache.Update(activity); PXRedirectHelper.TryRedirect(cache.Graph, windowMode); }