Having Trouble using filter function in NESTED CDT

Certified Associate Developer

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
                    			}
                    	},
                    
                    
                    }

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

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

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

     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

  • 0
    Certified Lead Developer
    in reply to Muhammad Ahmed

    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
    )

Reply
  • 0
    Certified Lead Developer
    in reply to Muhammad Ahmed

    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
    )

Children
No Data