Developer Q&A

Ask a Question
Back to All

Property Floor Asset Tree

Hi,

I've gathered all the property, and its floors details and stored them.
The next step to build up all the asset trees till the task level and construct all into a hierarchy model (json model) in which we could have all in one document to run a task level name text search.

In order to construct the hierarchy model, I am running the following query to collect the first level data ( Distance = 1 ) based on the parent Id, sequentially continues and eventually access the task.

    public static async Task<CorrigoEntity[]> RetrieveByQuery(CorrigoService service, int parentId)
    {
        var request = new RetrieveMultipleRequest();
        request.queryExpression = new QueryExpression
        {
            EntityType = EntityType.AssetTree,
            PropertySet = new PropertySet()
            {
                Properties = new string[]
                {
                                "Id",
                                "ParentId",
                                "ChildId",
                                "Child.*",
                                "Child.Address.*",
                                "Distance"
                }
            },
            Criteria = new FilterExpression
            {
                Conditions = new ConditionExpression[]
                {
                                new ConditionExpression
                                {
                                    PropertyName = "ParentId",
                                    Operator = ConditionOperator.Equal,
                                    Values = new object[] { parentId }
                                },
                                new ConditionExpression
                                {
                                    PropertyName = "Distance",
                                    Operator = ConditionOperator.Equal,
                                    Values = new object[] { 1 }
                                }
                },
            }
        };
        var result =  await service.RetrieveMultipleAsync(request);
        return result.RetrieveMultipleResult as CorrigoEntity[];
    }

Let's assume that the parent (originally an asset Id) is 14245.

The query pulls out the level 1 (distance = 1 ) data and the parent Id is assigned as 14245.

If I do not have a condition of distance = 1 then the rest of the hierarchy becomes available with the parent Id 14245 as well. It does not help me to understand which item belongs to which level.

And it continues till the end. However, the issue occurs that there is a server connection that drops constantly and not possible to finalise the process.

what is the best way to pull out all the hierarchy that provides and distinguishes clearly parent-child relation?

Thanks