You can use the View Manager service to create, read, and update Relativity views. This service also includes methods for retrieving the following information:
You can use the View Manager service to add or modify views used in a custom application or through the Relativity UI. For example, you might want to create a view that uses a specific set of search criteria to display custom objects in an application.
The REST API also supports the View Manager service. For more information, see View Manager (REST).
This page contains the following information:
In addition, the Relativity.Service.View namespace contains the following classes for use with this service:
For reference information about these classes and methods, see Relativity.Services.View.
Use the CreateSingleAsync() method to add a new view to a Relativity workspace. When calling this method, pass the Artifact ID of the workspace where you want to create the view, and a View object. This method returns the Artifact ID of the newly created view.
public async Task<bool> CreateSingleAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { View view = new View(); view.ArtifactTypeID = (int)ArtifactType.Document; view.Name = "My View"; List<UserRef> viewhOwners = await proxy.GetViewOwnersAsync(this.SampleWorkspace_ID); view.Owner = viewhOwners.First(o => o.ArtifactID == _PUBLIC_OWNER_ARTIFACT_ID); view.Fields.Add(new FieldRef("Control Number")); view.Fields.Add(new FieldRef("File Size")); Criteria fileSizeCriteria = new Criteria(); fileSizeCriteria.Condition = new CriteriaCondition() { FieldIdentifier = new FieldRef("File Size"), Operator = CriteriaConditionEnum.GreaterThan, Value = 2000 }; view.SearchCriteria.Conditions.Add(fileSizeCriteria); Services.Sort fileSizeSort = new Services.Sort() { FieldIdentifier = new FieldRef("File Size"), Direction = Services.SortEnum.Descending, Order = 1 }; view.Sorts.Add(fileSizeSort); view.Order = 100; view.VisibleInDropdown = true; view.Dashboard = new Services.DashboardObject.DashboardRef(this.SampleDashboardArtifact_ID); int artifactID = await proxy.CreateSingleAsync(this.SampleWorkspace_ID, view); if (artifactID != 0) { success = true; logger.LogInformation($"CreateSingleAsync succeeded. ArtifactID is {artifactID}."); } else { logger.LogError("CreateSingleAsync failed"); } } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } } return success; }
Use the ReadSingleAsync() method to retrieve information about a view. When calling this method, pass the Artifact ID of the workspace where the view resides, and the Artifact ID of the view. This method returns a View object.
public async Task<bool> ReadSingleAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { int? viewToReadArtifactID; if (ViewHelper.TryCreate(proxy, helper, this.SampleWorkspace_ID, "My View to Read", out viewToReadArtifactID)) { View view = await proxy.ReadSingleAsync(this.SampleWorkspace_ID, viewToReadArtifactID.Value); logger.LogInformation($"ReadSingleAsync succeeded. View ArtifactID is {view.ArtifactID}, Name is {view.Name}."); success = true; } } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } } return success; }
You can use the RetrieveAllViewsAsync() method to see each view in a workspace for a specific Artifact ID. To learn more, visit
public async Task<ViewResponse[]> RetrieveAllViewsAsync(int workspaceArtifactID, int artifactTypeID) { using (IViewManager viewManager = serviceFactory.CreateProxy<IViewManager>()) { ViewResponse[] viewResponses = await viewManager.RetrieveViewsByContextArtifactIDAsync(workspaceArtifactID, artifactTypeID); return viewResponses; } }
You can use the RetrieveAllViewsForSearchAsync() method to see each view that is associated with a saved search in a workspace. To learn more, visit
public async Task<SearchViewResponse[]> RetrieveAllViewsForSearchAsync(int workspaceArtifactID) { using (IViewManager viewManager = serviceFactory.CreateProxy<IViewManager>()) { SearchViewResponse[] searchViewResponses = await viewManager.RetrieveViewsByContextArtifactIDForSearchAsync(workspaceArtifactID); return searchViewResponses; } }
You can modify the properties of a view by calling the UpdateSingleAsync() method. When calling this method, pass the Artifact ID of the workspace where the view resides, and a View object.
public async Task<bool> UpdateSingleAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { int? viewToUpdateArtifactID; if (ViewHelper.TryCreate(proxy, this.SampleWorkspace_ID, "My View to Update", out viewToUpdateArtifactID)) { View view = await proxy.ReadSingleAsync(this.SampleWorkspace_ID, viewToUpdateArtifactID.Value); view.Name = $"{view.Name} - updated"; view.Fields.Add(new FieldRef("File Type")); Criteria fileTypeCriteria = new Criteria(); fileTypeCriteria.Condition = new CriteriaCondition() { FieldIdentifier = new FieldRef("File Type"), Operator = CriteriaConditionEnum.IsLike, Value = "document" }; view.SearchCriteria.Conditions.Add(fileTypeCriteria); Services.Sort fileTypeSort = new Services.Sort() { FieldIdentifier = new FieldRef("File Type"), Direction = Services.SortEnum.Ascending, Order = 200 }; view.Sorts.Add(fileTypeSort); await proxy.UpdateSingleAsync(this.SampleWorkspace_ID, view); logger.LogInformation($"UpdateSingleAsync succeeded."); success = true; } } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } }
You can use the GetAccessStatusAsync() method to determine whether a user has View permissions to a view, and to the fields used in the criteria for search conditions on the view. When calling this method, pass in the Artifact ID of the workspace, and that of the Artifact ID of the view that you want to check for user access status. The method returns a ViewAccessStatus object, which has CanView and CanViewCriteriaFields properties on it.
public async Task<bool> GetAccessStatusAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { int? viewToGetAccecStatusToArtifactID; if (ViewHelper.TryCreate(proxy, this.SampleWorkspace_ID, "My View to Get Access Status to", out viewToGetAccecStatusToArtifactID)) { ViewAccessStatus status = await proxy.GetAccessStatusAsync(this.SampleWorkspace_ID, viewToGetAccecStatusToArtifactID.Value); logger.LogInformation($"GetAccessStatusAsync succeeded. Exists is {status.Exists}, CanView is {status.CanView}, CanViewCriteriaFields is {status.CanViewCriteriaFields}"); success = true; } } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } } return success; }
You can use the GetViewOwnersAsync() method to retrieve a list of users in a workspace. You can then use this list to assign owners to a view. To be designated as an owner, a user must have View permissions for views. For more information, see
public async Task<bool> GetViewOwnersAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { IEnumerable<UserRef> owners = await proxy.GetViewOwnersAsync(this.SampleWorkspace_ID); logger.LogInformation($"GetViewOwnersAsync succeeded. Count of possible owners is {owners.Count()}"); success = true; } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } } return success; }
The GetObjectTypesAsync() method returns a list of object types residing in the workspace. You can select an object type from this list that is used for populating the ObjectType property on the View object. Call this method by passing Artifact ID of the workspace where the view exists. It returns a list of ObjectTypeRef objects.
public async Task<bool> GetObjectTypesAsync(IHelper helper) { bool success = false; using (IViewManager proxy = helper.GetServicesManager().CreateProxy<IViewManager>(ExecutionIdentity.User)) { Logging.ISampleLogger logger = _logger.ForContext("MethodName", new StackFrame(0).GetMethod().Name, false); try { IEnumerable<ObjectTypeRef> objectTypes = await proxy.GetObjectTypesAsync(this.SampleWorkspace_ID); logger.LogInformation($"GetObjectTypesAsync succeeded. Count of available object types is {objectTypes.Count()}"); success = true; } catch (Exception ex) { logger.LogError(ex, "Unhandled Exception"); } } return success; }
Community Updates |
|||
Aero Developer FAQ | Evolving the Platform | Most recent release notes | |
Learn more | Learn more | Learn more |
Additional Resources |
|||
![]() |
![]() |
||
Access Third-Party Tools with GitHub | Create .NET Apps Faster with NuGet | ||
Visit github | visit nuget |