{"id":5005,"date":"2018-08-03T10:32:58","date_gmt":"2018-08-03T05:02:58","guid":{"rendered":"\/?p=5005"},"modified":"2020-01-08T18:22:51","modified_gmt":"2020-01-08T12:52:51","slug":"how-to-change-data-type-typecast-in-aem-use-typehint","status":"publish","type":"post","link":"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/","title":{"rendered":"How to Change Data Type in AEM | Typecast Using @TypeHint"},"content":{"rendered":"
Problem Statement:<\/b><\/h5>\n

How to convert a variable from one data type to another data type in AEM. This process is also known as typecast in AEM.<\/p>\n

For a use case where a number field is used in dialog and further data will be utilized in\u00a0Sightly\u00a0(HTL) for numeric comparison operations. Problem can come up as data will be stored in String format and comparison can only be made on same data type elements.<\/p>\n

Solution:<\/b><\/h5>\n

Using @TypeHint, which is used to forcefully define the data type of a property. The following are the steps and scenarios for the application of the same to change data type in AEM.<\/p>\n

Scenario:<\/b><\/h5>\n

I have a number field in my dialog with name ‘sponsoredPosition’. By default its value is stored in String format and I wanted it to be stored in Long format instead of String format.<\/p>\n

Steps to Change Data Type in AEM using @TypeHint<\/b><\/h5>\n

In the component, add a node parallel to the ‘sponsoredPosition’ node (for which data type needs to be changed) of the type nt:unstructured.<\/p>\n

    \n
  1. In the new node add the following properties:<\/li>\n
  2. ignoreData{Boolean} = true<\/li>\n
  3. value{String} = Long<\/li>\n
  4. Name{String} =sponsoredPosition@TypeHint<\/li>\n
  5. sling:resourceType{String} =\u00a0\u00a0 granite\/ui\/components\/foundation\/form\/hidden.<\/li>\n<\/ol>\n

    Here,<\/p>\n

    (a) ignoreData, as the name suggests, it tells the value of this field should not be stored.<\/p>\n

    (b) In value field you must define the data type in which you want your data to be stored.<\/p>\n

    (c) In Name field add \u2018@TypeHint\u2019 suffix to the property name of original node whose value was stored in string format (by default).<\/p>\n

    (d) Resource type\u00a0hidden is\u00a0used for hiding it in dialog.<\/p>\n

    <sponsoredPosition\r\n  jcr:primaryType=\"nt:unstructured\"\r\n  sling:resourceType=\"granite\/ui\/components\/foundation\/form\/numberfield\"\r\n  fieldLabel=\"Sponsored Content Position\"\r\n  max=\"{Long}3\"\r\n  min=\"{Long}2\"\r\n  value=\"3\"\r\n  name=\".\/sponsoredPosition\"\/>\r\n  <sponsoredPositionTypeHint\r\n    jcr:primaryType=\"nt:unstructured\"\r\n    sling:resourceType=\"granite\/ui\/components\/foundation\/form\/hidden\"\r\n    ignoreData=\"{Boolean}true\"\r\n    name=\".\/sponsoredPosition@TypeHint\"\r\n    value=\"Long\"\/><\/pre>\n

    This article is intended to provide technical AEM users a solution and tactical training on the topic: How to change data type in AEM or how to typecast in AEM.<\/p>\n

    Conclusion<\/b><\/h5>\n

    Adding @TypeHint\u00a0solved the issue, now\u00a0value is being stored in Long format instead of String.<\/p>\n

    Interested in more AEM CMS training and support for your organisation? Request a consultation<\/a>\u00a0to discuss Argil DX managed services.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Problem Statement: How to convert a variable from one data type to another data type in AEM. This process is also known as typecast in AEM. For a use case where a number field is used in dialog and further data will be utilized in\u00a0Sightly\u00a0(HTL) for numeric comparison operations. Problem can come up as data … Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":6657,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","content-type":"","footnotes":""},"categories":[66],"tags":[91,93,43,1835],"yst_prominent_words":[534,1840,1838,1836,1820,1837,1825,1822,1831,1449,1830,1826,1829,1823,1824,1821,1827,1839,1841,1842],"acf":[],"yoast_head":"\nHow to Change Data Type in AEM or Data Typecast using @TypeHint<\/title>\n<meta name=\"description\" content=\"How to change data type in AEM using @TypeHint, which helps in defining the\u00a0data\u00a0type of a\u00a0property. Also known as data typecast, this process is explained.\" \/>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Change Data Type in AEM or Data Typecast using @TypeHint\" \/>\n<meta property=\"og:description\" content=\"How to change data type in AEM using @TypeHint, which helps in defining the\u00a0data\u00a0type of a\u00a0property. Also known as data typecast, this process is explained.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/\" \/>\n<meta property=\"og:site_name\" content=\"Argil DX\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-03T05:02:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-08T12:52:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.argildx.us\/wp-content\/uploads\/2018\/08\/How-to-Change-Data-Type-Typecast-in-AEM-Use-@TypeHint.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1440\" \/>\n\t<meta property=\"og:image:height\" content=\"542\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.argildx.us\/#website\",\"url\":\"https:\/\/www.argildx.us\/\",\"name\":\"Argil DX\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.argildx.us\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.argildx.us\/wp-content\/uploads\/2018\/08\/How-to-Change-Data-Type-Typecast-in-AEM-Use-@TypeHint.jpg\",\"width\":1440,\"height\":542,\"caption\":\"How to Change Data Type (Typecast) in AEM, Use @TypeHint\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/#webpage\",\"url\":\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/\",\"name\":\"How to Change Data Type in AEM or Data Typecast using @TypeHint\",\"isPartOf\":{\"@id\":\"https:\/\/www.argildx.us\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/#primaryimage\"},\"datePublished\":\"2018-08-03T05:02:58+00:00\",\"dateModified\":\"2020-01-08T12:52:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.argildx.us\/#\/schema\/person\/7583783869e92b1d4ccd40dbb2aef076\"},\"description\":\"How to change data type in AEM using @TypeHint, which helps in defining the\\u00a0data\\u00a0type of a\\u00a0property. Also known as data typecast, this process is explained.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.argildx.us\/technology\/how-to-change-data-type-typecast-in-aem-use-typehint\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.argildx.us\/#\/schema\/person\/7583783869e92b1d4ccd40dbb2aef076\",\"name\":\"Arpit Rathi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.argildx.us\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/20e56987516b8528ddbcb4f9fa8aabe6?s=96&d=mm&r=g\",\"caption\":\"Arpit Rathi\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","_links":{"self":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts\/5005"}],"collection":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/comments?post=5005"}],"version-history":[{"count":0,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/posts\/5005\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/media\/6657"}],"wp:attachment":[{"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/media?parent=5005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/categories?post=5005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/tags?post=5005"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.argildx.us\/wp-json\/wp\/v2\/yst_prominent_words?post=5005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}