{"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":"
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
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
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
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
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>\nThis 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":"\n
How to Change Data Type in AEM or Data Typecast using @TypeHint<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\n