Skip to main content
muhammada5142
January 9, 2026
Solved

Having Trouble using filter function in NESTED CDT

  • January 9, 2026
  • 5 replies
  • 0 views

Hi Everyone,

I have requirement to retrieve resulting CDT list by filtering nested CDT list containing key-value Tier:1 in nested CDT.

This is CDT list

     local: list    {
                    	{
                    		ReportFacilityId:30803, 
                    		FacilityId:3551, 
                    		FormInstanceId:4271964, 
                    		FacilityName:"Test 1", 
                    		IsSectionLarger:false, 
                    		FacilityMode:
                    		{
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 1,
                    			Tier:1
                    			}, 
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 3,
                    			Tier:2
                    			}
                    		}
                    	},
                    	{
                    		ReportFacilityId:30804, 
                    		FacilityId:3552, 
                    		FormInstanceId:4271964, 
                    		FacilityName:"Test 1", 
                    		IsSectionLarger:false, 
                    		FacilityMode:
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 1,
                    			Tier:1
                    			},
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 1,
                    			Tier:2
                    			},
                    			
                    	},
                    
                    
                    }
                    
                    
                    
    /* what I want to retrieve is list with  Tier: 1 FacilityMode */
    filteredList: {
                    	{
                    		ReportFacilityId:30803, 
                    		FacilityId:3551, 
                    		FormInstanceId:4271964, 
                    		FacilityName:"Test 1", 
                    		IsSectionLarger:false, 
                    		FacilityMode:
                    		{
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 1,
                    			Tier:1
                    			}
                    		}
                    	},
                    	{
                    		ReportFacilityId:30804, 
                    		FacilityId:3552, 
                    		FormInstanceId:4271964, 
                    		FacilityName:"Test 1", 
                    		IsSectionLarger:false, 
                    		FacilityMode:
                    			{
                    			A15LinkModeId:17394, 
                    			ModeId:4, 
                    			ToS: 1,
                    			Tier:1
                    			}
                    	},
                    
                    
                    }

Best answer by shubhama926776

Check this

a!localVariables(
  local!data: {
    {
      ReportFacilityId: 30803,
      FacilityId: 3551,
      FormInstanceId: 4271964,
      FacilityName: "Test 1",
      IsSectionLarger: false,
      FacilityMode: {
        {
          A15LinkModeId: 17394,
          ModeId: 4,
          ToS: 1,
          Tier: 1
        },
        {
          A15LinkModeId: 17395,
          ModeId: 4,
          ToS: 3,
          Tier: 2
        }
      },
      Latitude: "33.3333000",
      Longitude: "-66.6666000",
      YearBuilt: 2017,
      FacilityTypeId: 12,
      SquareFeet: 55,
      PercAgCapResp: 1,
      PrivateModeId: 1,
      Notes: "Test test",
      IsNew: false,
      IsUpdated: false,
      IsDeleted: false,
      ReportYear: "2020"
    },
    {
      ReportFacilityId: 30804,
      FacilityId: 3552,
      FormInstanceId: 4271964,
      FacilityName: "Test 2",
      IsSectionLarger: false,
      FacilityMode: {
        {
          A15LinkModeId: 17396,
          ModeId: 4,
          ToS: 1,
          Tier: 1
        },
        {
          A15LinkModeId: 17397,
          ModeId: 4,
          ToS: 1,
          Tier: 2
        }
      },
      Latitude: "33.3333000",
      Longitude: "-66.6666000",
      YearBuilt: 2017,
      FacilityTypeId: 12,
      SquareFeet: 55,
      PercAgCapResp: 1,
      PrivateModeId: 1,
      Notes: "Test test",
      IsNew: false,
      IsUpdated: false,
      IsDeleted: false,
      ReportYear: "2020"
    }
  },
  local!filteredResult: a!forEach(
    items: local!data,
    expression: a!update(
      fv!item,
      "FacilityMode",
      {index(fv!item.FacilityMode, 1, null)}
    )
  ),
  local!filteredResult
)

5 replies

stefanhelzle0001
January 9, 2026

Did you consider to use the filter function with a separate predicate function?

muhammada5142
January 9, 2026

 local!data: 
 {
	{
		ReportFacilityId:30803, 
		FacilityId:3551, 
		FormInstanceId:4271964, 
		FacilityName:"Test 1", 
		IsSectionLarger:false, 
		FacilityMode:
		{
			{
			A15LinkModeId:17394, 
			ModeId:4, 
			ToS: 1,
			Tier:1
			}, 
			{
			A15LinkModeId:17395, 
			ModeId:4, 
			ToS: 3,
			Tier:2
			}, 
		},
		Latitude:"33.3333000", 
		Longitude:"-66.6666000", 
		YearBuilt:2017, 
		FacilityTypeId:12, 
		SquareFeet:55, 
		PercAgCapResp:1, 
		PrivateModeId:1, 
		Notes:"Test test", 
		IsNew:false, 
		IsUpdated:false, 
		IsDeleted:false, 
		ReportYear:"2020"
	},
	{
		ReportFacilityId:30803, 
		FacilityId:3552, 
		FormInstanceId:4271964, 
		FacilityName:"Test 1", 
		IsSectionLarger:false, 
		FacilityMode:{
			{
			A15LinkModeId:17396, 
			ModeId:4, 
			ToS: 1,
			Tier:1
			}, 
			{
			A15LinkModeId:17397, 
			ModeId:4, 
			ToS: 1,
			Tier:2
			},
		},
		Latitude:"33.3333000", 
		Longitude:"-66.6666000", 
		YearBuilt:2017, 
		FacilityTypeId:12, 
		SquareFeet:55, 
		PercAgCapResp:1, 
		PrivateModeId:1, 
		Notes:"Test test", 
		IsNew:false, 
		IsUpdated:false, 
		IsDeleted:false, 
		ReportYear:"2020"
	}
}
 local!filteredResult:  a!forEach(
   items: local!data,
   expression: 
   fv!item.FacilityMode[1]
 ),

The result is 

{

{
A15LinkModeId:17394,
ModeId:4,
ToS: 1,
Tier:1
},

{
A15LinkModeId:17396,
ModeId:4,
ToS: 1,
Tier:1
},

}.

What I want is the whole object with nested A15LinkMode. It would always be the case where I want to retrive first index of nested CDT