//TODO: Check this method and the token object and take a look into the precision field; private ZCRMField GetZCRMField(JObject fieldJSON) { ZCRMField field = ZCRMField.GetInstance(Convert.ToString(fieldJSON["api_name"])); field.DefaultValue = (object)fieldJSON["default_value"]; field.Mandatory = Convert.ToBoolean(fieldJSON["required"]); field.Id = Convert.ToInt64(fieldJSON["id"]); field.CustomField = Convert.ToBoolean(fieldJSON["custom_field"]); field.DataType = Convert.ToString(fieldJSON["data_type"]); field.DisplayName = Convert.ToString(fieldJSON["field_label"]); field.MaxLength = (int?)fieldJSON["length"]; field.Precision = (int?)fieldJSON["decimal_place"]; field.ReadOnly = Convert.ToBoolean(fieldJSON["read_only"]); field.Visible = Convert.ToBoolean(fieldJSON["visible"]); field.SequenceNo = (int?)fieldJSON["sequence_number"]; field.ToolTip = Convert.ToString(fieldJSON["tooltip"]); field.Webhook = Convert.ToBoolean(fieldJSON["webhook"]); field.CreatedSource = Convert.ToString(fieldJSON["created_source"]); JToken tempJSONObect = fieldJSON["formula"]; if (tempJSONObect.HasValues) { field.FormulaReturnType = Convert.ToString(fieldJSON["return_type"]); } tempJSONObect = fieldJSON["currency"]; if (tempJSONObect.HasValues) { field.Precision = (int?)fieldJSON["precision"]; } JObject subLayouts = (JObject)fieldJSON["view_type"]; if (subLayouts != null) { List <string> layoutsPresent = new List <string>(); if (Convert.ToBoolean(subLayouts["create"])) { layoutsPresent.Add("CREATE"); } if (Convert.ToBoolean(subLayouts["view"])) { layoutsPresent.Add("VIEW"); } if (Convert.ToBoolean(subLayouts["quick_create"])) { layoutsPresent.Add("QUICK_CREATE"); } field.SubLayoutsPresent = layoutsPresent; } JArray pickList = (JArray)fieldJSON["pick_list_values"]; foreach (JObject pickListObject in pickList) { ZCRMPickListValue pickListValue = ZCRMPickListValue.GetInstance(); pickListValue.DisplayName = Convert.ToString(fieldJSON["display_value"]); pickListValue.ActualName = Convert.ToString(fieldJSON["actual_value"]); pickListValue.SequenceNumber = Convert.ToInt32(fieldJSON["sequence_number"]); pickListValue.Maps = (JArray)fieldJSON["maps"]; field.AddPickListValue(pickListValue); } JObject lookup = (JObject)fieldJSON["lookup"]; foreach (KeyValuePair <string, JToken> lookupObject in lookup) { field.SetLookupDetails(lookupObject.Key, (object)lookupObject.Value); } JObject multilookup = (JObject)fieldJSON["multiselectlookup"]; foreach (KeyValuePair <string, JToken> multiLookupObject in multilookup) { field.SetMultiselectLookup(multiLookupObject.Key, (object)multiLookupObject.Value); } if (fieldJSON.ContainsKey("subformtabId")) { field.SubFormTabId = Convert.ToInt64(fieldJSON["subformtabid"]); } if (fieldJSON.ContainsKey("subform")) { JObject subformDetails = (JObject)fieldJSON["subform"]; foreach (KeyValuePair <string, JToken> subformDetail in subformDetails) { field.SetSubformDetails(subformDetail.Key, (object)subformDetail.Value); } } return(field); }
private ZCRMField GetZCRMField(JObject fieldJSON) { ZCRMField field = ZCRMField.GetInstance(Convert.ToString(fieldJSON["api_name"])); field.Mandatory = (bool?)fieldJSON["system_mandatory"]; field.Webhook = (bool)(fieldJSON["webhook"]); field.JsonType = (string)(fieldJSON["json_type"]); if (fieldJSON["crypt"].HasValues) { foreach (KeyValuePair <string, JToken> crypt in (JObject)fieldJSON["crypt"]) { field.SetEncrypt(crypt.Key, Convert.ToString(crypt.Value)); } } field.DisplayName = (string)(fieldJSON["field_label"]); if (fieldJSON["tooltip"].HasValues) { JObject tool_tip = (JObject)fieldJSON["tooltip"]; field.FieldToolTip = ZCRMToolTip.GetInstance((string)(tool_tip["name"]), (string)(tool_tip["value"])); field.ToolTip = (string)(tool_tip["name"]); } field.CreatedSource = (string)(fieldJSON["created_source"]); field.FieldReadOnly = (bool)(fieldJSON["field_read_only"]); field.DisplayLabel = (string)(fieldJSON["display_label"]); field.ReadOnly = (bool)(fieldJSON["read_only"]); if (fieldJSON["association_details"].HasValues) { foreach (KeyValuePair <string, JToken> association_details in (JObject)fieldJSON["association_details"]) { if (association_details.Key.Equals("lookup_field")) { JObject data = (JObject)association_details.Value; ZCRMField field_obj = ZCRMField.GetInstance(Convert.ToString(data["api_name"])); field_obj.Id = Convert.ToInt64(data["id"]); field.SetAssociationDetails(association_details.Key, field_obj); } if (association_details.Key.Equals("related_field")) { JObject data = (JObject)association_details.Value; ZCRMField field_obj = ZCRMField.GetInstance(Convert.ToString(data["api_name"])); field_obj.Id = Convert.ToInt64(data["id"]); field.SetAssociationDetails(association_details.Key, field_obj); } } } if (fieldJSON.ContainsKey("businesscard_supported")) { field.BusinesscardSupported = (bool)(fieldJSON["businesscard_supported"]); } if (fieldJSON["currency"].HasValues) { JObject tempJSONObject = (JObject)fieldJSON["currency"]; if (tempJSONObject.HasValues) { if (tempJSONObject.ContainsKey("precision")) { field.Precision = (int?)tempJSONObject["precision"]; } if (tempJSONObject.ContainsKey("rounding_option")) { field.RoundingOption = Convert.ToString(tempJSONObject["rounding_option"]); } } } field.Id = (long)(fieldJSON["id"]); field.CustomField = (bool)(fieldJSON["custom_field"]); if (fieldJSON["lookup"].HasValues) { JObject lookup = (JObject)fieldJSON["lookup"]; foreach (KeyValuePair <string, JToken> lookupObject in lookup) { field.SetLookupDetails(lookupObject.Key, (object)lookupObject.Value); } } field.Visible = (bool)(fieldJSON["visible"]); field.MaxLength = (int?)fieldJSON["length"]; JObject subLayouts = (JObject)fieldJSON["view_type"]; if (subLayouts.Type != JTokenType.Null) { List <string> layoutsPresent = new List <string>(); if ((bool)subLayouts["create"]) { layoutsPresent.Add("CREATE"); } if ((bool)subLayouts["view"]) { layoutsPresent.Add("VIEW"); } if ((bool)subLayouts["quick_create"]) { layoutsPresent.Add("QUICK_CREATE"); } if ((bool)subLayouts["edit"]) { layoutsPresent.Add("EDIT"); } field.SubLayoutsPresent = layoutsPresent; } if (fieldJSON["subform"].HasValues) { JObject subformDetails = (JObject)fieldJSON["subform"]; foreach (KeyValuePair <string, JToken> subformDetail in subformDetails) { field.SetSubformDetails(subformDetail.Key, (object)subformDetail.Value); } } if (fieldJSON["unique"].HasValues) { field.UniqueField = true; JObject casesensitive = (JObject)fieldJSON["unique"]; if (casesensitive != null) { field.CaseSensitive = (string)(casesensitive["casesensitive"]); } } if (fieldJSON.ContainsKey("history_tracking") && fieldJSON["history_tracking"].Type != JTokenType.Null) { field.HistoryTracking = (bool)(fieldJSON["history_tracking"]); } field.DataType = (string)(fieldJSON["data_type"]); if (fieldJSON["formula"].HasValues) { JObject tempJSONObject = (JObject)fieldJSON["formula"]; if (tempJSONObject.HasValues) { if (tempJSONObject.ContainsKey("return_type")) { field.FormulaReturnType = (string)(tempJSONObject["return_type"]); } if (tempJSONObject.ContainsKey("expression")) { field.FormulaExpression = (string)(tempJSONObject["expression"]); } } } field.DecimalPlace = (int?)fieldJSON["decimal_place"]; if (fieldJSON.ContainsKey("mass_update")) { field.MassUpdate = (bool)(fieldJSON["mass_update"]); } if (fieldJSON.ContainsKey("blueprint_supported") && fieldJSON["blueprint_supported"].Type != JTokenType.Null) { field.BluePrintSupported = (bool)(fieldJSON["blueprint_supported"]); } if (fieldJSON["pick_list_values"].HasValues) { JArray pickList = (JArray)fieldJSON["pick_list_values"]; foreach (JObject pickListObject in pickList) { ZCRMPickListValue pickListValue = ZCRMPickListValue.GetInstance(); pickListValue.DisplayName = (string)pickListObject["display_value"]; pickListValue.ActualName = (string)pickListObject["actual_value"]; pickListValue.SequenceNumber = Convert.ToInt32(pickListObject["sequence_number"]); pickListValue.Maps = (JArray)pickListObject["maps"]; field.AddPickListValue(pickListValue); } } if (fieldJSON["multiselectlookup"].HasValues) { JObject multilookup = (JObject)fieldJSON["multiselectlookup"]; foreach (KeyValuePair <string, JToken> multiLookupObject in multilookup) { field.SetMultiselectLookup(multiLookupObject.Key, (object)multiLookupObject.Value); } } if (fieldJSON["auto_number"].HasValues) { field.AutoNumber = true; JObject auto_number = (JObject)fieldJSON["auto_number"]; if (auto_number.ContainsKey("prefix") && auto_number["prefix"].Type != JTokenType.Null) { field.Prefix = Convert.ToString(auto_number["prefix"]); } if (auto_number.ContainsKey("suffix") && auto_number["suffix"].Type != JTokenType.Null) { field.Suffix = Convert.ToString(auto_number["suffix"]); } if (auto_number.ContainsKey("start_number") && auto_number["start_number"].Type != JTokenType.Null) { field.StartNumber = Convert.ToInt32(auto_number["start_number"]); } } if (fieldJSON.ContainsKey("default_value") && fieldJSON["default_value"].Type != JTokenType.Null) { field.DefaultValue = (object)fieldJSON["default_value"]; } if (fieldJSON.ContainsKey("sequence_number") && fieldJSON["sequence_number"].Type != JTokenType.Null) { field.SequenceNo = (int?)fieldJSON["sequence_number"]; } if (fieldJSON.ContainsKey("subformtabId") && fieldJSON["subformtabId"].Type != JTokenType.Null) { field.SubFormTabId = Convert.ToInt64(fieldJSON["subformtabid"]); } return(field); }