how to extract year from date and time with timezone

Certified Associate Developer

I have record which has " created on "field. I wanted to filter all records that is created for this year. But when I try to convert the created on field to year for comparison. It shows error. 

Expression evaluation error at function a!queryRecordType: Could not cast from Record Field to Date. Details: CastInvalidCould not cast from Record Field to Date. Details: CastInvalid

Any help is appreciated

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hello ,

    Create a custom record field shown as below


    Select the field where your Date and Time value exists




    Then Create a user filter from the Filters in a expression mode

    Here's a code snippet if needed for reference, replace the field here with your custom record field value and test it out.

    a!localVariables(
      local!year:a!queryRecordType(
        recordType: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request',
        fields: a!aggregationFields(
          groupings: {
            a!grouping(
              field: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request.fields.{0c614836-7916-4250-acf6-a19403f6dd18}raisedonYear',
              alias: "year"
            )
          }
        ),
        pagingInfo: a!pagingInfo(startIndex: 1,batchSize: 5000)
      ).data,
      a!recordFilterList(
        name: "Year",
        options: a!forEach(
          items: index(local!year,"year",""),
          expression: a!recordFilterListOption(
            id: fv!index,
            name: fv!item,
            filter: a!queryFilter(
              field: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request.fields.{0c614836-7916-4250-acf6-a19403f6dd18}raisedonYear',
              operator: "=",
              value: fv!item
            )
          )
        )
      )
    )

    Below is the outcome of the above 

Reply
  • 0
    Certified Senior Developer

    Hello ,

    Create a custom record field shown as below


    Select the field where your Date and Time value exists




    Then Create a user filter from the Filters in a expression mode

    Here's a code snippet if needed for reference, replace the field here with your custom record field value and test it out.

    a!localVariables(
      local!year:a!queryRecordType(
        recordType: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request',
        fields: a!aggregationFields(
          groupings: {
            a!grouping(
              field: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request.fields.{0c614836-7916-4250-acf6-a19403f6dd18}raisedonYear',
              alias: "year"
            )
          }
        ),
        pagingInfo: a!pagingInfo(startIndex: 1,batchSize: 5000)
      ).data,
      a!recordFilterList(
        name: "Year",
        options: a!forEach(
          items: index(local!year,"year",""),
          expression: a!recordFilterListOption(
            id: fv!index,
            name: fv!item,
            filter: a!queryFilter(
              field: 'recordType!{55d40bd2-3986-4477-bd9f-627d5a979404}STE Asset Request.fields.{0c614836-7916-4250-acf6-a19403f6dd18}raisedonYear',
              operator: "=",
              value: fv!item
            )
          )
        )
      )
    )

    Below is the outcome of the above 

Children
No Data