/// <summary> /// Gets the property value. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="properties">The properties.</param> /// <returns></returns> private static object GetPropertyValue(string fieldName, SPItemEventProperties properties) { try { var value = properties.AfterProperties[fieldName]; if (value == null) { var listItem = SaveDataJobExecuteCache.GetListItem(properties); if (listItem != null) { if (listItem.Fields.ContainsFieldWithInternalName(fieldName)) { value = listItem[fieldName]; var list = SaveDataJobExecuteCache.GetList(properties); var spField = list.Fields.GetFieldByInternalName(fieldName); if (spField.Type == SPFieldType.DateTime) { value = SPUtility.CreateISO8601DateTimeFromSystemDateTime(Convert.ToDateTime(value.ToString())); } } } } return(value ?? string.Empty); } catch { return(string.Empty); } }
private static void GetStatus(SPItemEventProperties properties, ref string status) { try { if (properties.AfterProperties["Status"] == null) { var list = SaveDataJobExecuteCache.GetList(properties); if (list.Fields["Status"].DefaultValue != null) { status = list.Fields["Status"].DefaultValue; } } else { status = properties.AfterProperties["Status"].ToString(); } } catch (Exception ex) { Trace.TraceError("Exception Suppressed {0}", ex); } }
private static bool VerifyHiddenItems(SPItemEventProperties properties) { var allHidden = true; try { var list = SaveDataJobExecuteCache.GetList(properties); foreach (DictionaryEntry field in properties.AfterProperties) { if (!list.Fields.GetFieldByInternalName(field.Key.ToString()).Hidden) { allHidden = false; break; } } } catch (Exception ex) { Trace.TraceError("Exception Suppressed {0}", ex); allHidden = false; } return(!allHidden); }
/// <summary> /// Copies the schedule field value to PC field. /// </summary> /// <param name="properties">The properties.</param> private static void CopyScheduleFieldValueToPCField(SPItemEventProperties properties) { var list = SaveDataJobExecuteCache.GetList(properties); if (list.Fields.ContainsFieldWithInternalName("ProjectUpdate")) { var propertyValue = GetPropertyValue("ProjectUpdate", properties); //SKYVERA-455: if project update is schedule driven but project is closed, we should avoid automatic updates for project fields if (propertyValue != null && (!propertyValue.ToString().Equals(TypeScheduleDriven) || (list.Fields.ContainsFieldWithInternalName(StateFieldName) && properties.AfterProperties[StateFieldName].ToString().EndsWith(ClosedState, StringComparison.OrdinalIgnoreCase)))) { return; } foreach (SPField spField in list.Fields) { if (spField.InternalName.IndexOf("project", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Match match = Regex.Match(spField.InternalName, @"^Project(.*?)$", RegexOptions.IgnoreCase); if (!match.Success) { continue; } string field = match.Groups[1].Value; if (!list.Fields.ContainsFieldWithInternalName(field)) { continue; } properties.AfterProperties[spField.InternalName] = GetPropertyValue(field, properties); } } else if (list.Fields.ContainsFieldWithInternalName("PortfolioUpdate")) { var propertyValue = GetPropertyValue("PortfolioUpdate", properties); if (propertyValue != null && !propertyValue.ToString().Equals("Schedule Driven")) { return; } foreach (SPField spField in list.Fields) { if (spField.InternalName.IndexOf("portfolio", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Match match = Regex.Match(spField.InternalName, @"^Portfolio(.*?)$", RegexOptions.IgnoreCase); if (!match.Success) { continue; } string field = match.Groups[1].Value; if (!list.Fields.ContainsFieldWithInternalName(field)) { continue; } properties.AfterProperties[spField.InternalName] = GetPropertyValue(field, properties); } } }
public override void ItemUpdating(SPItemEventProperties properties) { bool allHidden = true; try { var list = SaveDataJobExecuteCache.GetList(properties); foreach (System.Collections.DictionaryEntry sField in properties.AfterProperties) { if (!list.Fields.GetFieldByInternalName(sField.Key.ToString()).Hidden) { allHidden = false; break; } } } catch { allHidden = false; } if (properties.AfterProperties["Publisher_x0020_Approval_x0020_S"] != null) { return; } if (!allHidden && properties.AfterProperties["IsPublished"] == null) { properties.AfterProperties["IsPublished"] = "0"; try { SPFieldLookupValue lv = new SPFieldLookupValue(SaveDataJobExecuteCache.GetListItem(properties)["Project"].ToString()); SPField f = SaveDataJobExecuteCache.GetList(properties).Fields.GetFieldByInternalName("Project"); XmlDocument doc = new XmlDocument(); doc.LoadXml(f.SchemaXml); string listid = doc.FirstChild.Attributes["List"].Value; var web = properties.Web; SPList list = web.Lists[new Guid(listid)]; SPListItem li = list.GetItemById(lv.LookupId); if (list.Fields.ContainsFieldWithInternalName("PendingUpdates")) { SPField fPend = list.Fields.GetFieldByInternalName("PendingUpdates"); string pending = ""; try { pending = fPend.GetFieldValueAsText(li[fPend.Id].ToString()); }catch {} if (pending != "Yes") { li[fPend.Id] = 1; li.SystemUpdate(); ArrayList arr = new ArrayList(); SPFieldUserValue uv = new SPFieldUserValue(web, li["Author"].ToString()); arr.Add(uv.LookupId); try { SPFieldUserValueCollection uvc = new SPFieldUserValueCollection(web, li["Planners"].ToString()); foreach (SPFieldUserValue u in uvc) { if (!arr.Contains(u.LookupId)) { arr.Add(u.LookupId); } } }catch {} try { SPFieldUserValueCollection uvc = new SPFieldUserValueCollection(web, li["Project Manager"].ToString()); foreach (SPFieldUserValue u in uvc) { if (!arr.Contains(u.LookupId)) { arr.Add(u.LookupId); } } } catch { } Hashtable hshProps = new Hashtable(); hshProps.Add("ProjectName", li.Title); hshProps.Add("ListId", list.ID.ToString()); hshProps.Add("ItemId", li.ID.ToString()); //string body = Properties.Resources.txtPendingUpdateEmail; //body = body.Replace("{ProjectName}", li.Title); //body = body.Replace("{ListId}", list.ID.ToString()); //body = body.Replace("{ItemId}", li.ID.ToString()); foreach (int i in arr) { try { //SPSecurity.RunWithElevatedPrivileges(delegate() //{ SPUser u = web.SiteUsers.GetByID(1073741823); API.APIEmail.QueueItemMessage(5, true, hshProps, new string[] { i.ToString() }, null, false, true, li, u, false); //}); //API.APIEmail.sendEmailHideReply(5, properties.SiteId, properties.Web.ID, properties.Web.CurrentUser, properties.Web.SiteUsers.GetByID(i), hshProps); } catch { } } } } } catch { } } }