/// <summary> /// Updates the provided web resource /// </summary> /// <param name="wr">Web resource to update</param> internal static void UpdateWebResource(this CrmServiceClient service, Entity wr) { try { var script = wr; if (!script.Contains("webresourceid")) { var existingEntity = service.RetrieveWebResource(script.Attributes["name"] as string); if (existingEntity == null) { script.Id = service.CreateWebResource(script); } else { script.Id = existingEntity.Id; if (!script.Contains("displayname") && existingEntity.Contains("displayname")) { script.Attributes.Add("displayname", existingEntity.Attributes["displayname"]); } if (!script.Contains("description") && existingEntity.Contains("description")) { script.Attributes.Add("description", existingEntity.Attributes["description"]); } service.Update(script); } } else { service.Update(script); } } catch (Exception error) { throw new Exception("Error while updating web resource: " + error.Message); } }