Skip to main content
Brainy
Dec 10, 2023 4:33 PM UTC
Question

how to extract year from date and time with timezone

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

    5 replies

    stefanhelzle0001
    Brainy
    Dec 10, 2023 6:42 PM UTC

    Can you share a few more details? Code snippets?

    Did you consider to use a custom record field that just holds the year part of that date?

    niranjanreddym9323
    Participating Frequently
    Dec 11, 2023 5:33 AM UTC

    Hi [mention:92ba06295fbc4d77b281c512999a858b:e9ed411860ed4f2ba0265705b8793d05] ,

    You can create a custom record field  'year' using extract partial dates template and refer this new custom field to filter the data that is created for this year.

    konduruc733182
    Inspiring
    Dec 11, 2023 12:21 PM UTC

    Hello kowsalyav7826,

    Create a custom record field shown as below



    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 

    New Participant
    Dec 11, 2023 12:53 PM UTC
    [deleted]
    konduruc733182
    Inspiring
    Dec 11, 2023 1:39 PM UTC

    I don't understand the audacity of these people creating accounts and making such post on a platform which is completely dedicated to Technical knowledge sharing. I think there should be more aggressive measures on such accounts.