{"id":193,"date":"2019-09-10T18:21:43","date_gmt":"2019-09-10T18:21:43","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=193"},"modified":"2020-09-08T14:55:34","modified_gmt":"2020-09-08T09:25:34","slug":"creating-a-custom-field-type-in-suitecrm","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/","title":{"rendered":"Creating a custom field type in SuiteCRM"},"content":{"rendered":"\n<p>Like a lot of SuiteCRM the field types are customisable and you can add your own types of fields. This post will explain how to add a colour picker as a custom field type.<\/p>\n\n\n\n<p>Steps are as below,<\/p>\n\n\n\n<p><strong>Setp 1:<\/strong> First off we need to add the option to studio to allow creating fields of our new type. We do this by adding a new file&nbsp;<code>custom\/modules\/DynamicFields\/templates\/Fields\/TemplateColourPicker.php<\/code>&nbsp;with the following contents: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');\n                            \/\/\nrequire_once('modules\/DynamicFields\/templates\/Fields\/TemplateField.php');\nclass TemplateColourPicker extends TemplateField{\n    var $type='ColourPicker';\n                            \/\/\n    function get_field_def(){\n        $def = parent::get_field_def();\n        $def['dbType'] = 'varchar';\n        return $def;\n    }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Setp 2:<\/strong> Next we create the language file&nbsp;<code>custom\/Extension\/modules\/ModuleBuilder\/Ext\/Language\/en_us.ColourPicker.php<\/code>&nbsp;and define the label for our new field type: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$mod_strings['fieldTypes']['ColourPicker'] = 'Colour Picker';<\/code><\/pre>\n\n\n\n<p><strong>Step 3:<\/strong>  After a quick repair and rebuild this gives us the option to create a field with type &#8220;Colour Picker&#8221;: <\/p>\n\n\n\n<ul class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"289\" height=\"300\" src=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png\" alt=\"\" data-id=\"194\" data-link=\"https:\/\/www.techcrm.in\/blogs\/?attachment_id=194\" class=\"wp-image-194\"\/><figcaption> This can then be added to views and the like through studio in the usual manner. <\/figcaption><\/figure><\/li><\/ul>\n\n\n\n<p><strong>Step 4:<\/strong>  However our field is pretty boring and doesn\u2019t do anything yet. Let\u2019s give it some personality.<\/p>\n\n\n\n<p>We\u2019ll use&nbsp;<a href=\"http:\/\/www.dematte.at\/tinyColorPicker\/\">TinyColorPicker<\/a>&nbsp;to add some functionality to the field. This will get saved in a new directory in  <code>custom\/include\/SugarFields\/Fields\/ColourPicker\/js\/jqColorPicker.min.js<\/code> <\/p>\n\n\n\n<p><strong>Step 5:<\/strong>  Next we\u2019ll add two templates, one for the Detail view at&nbsp;<code>custom\/include\/SugarFields\/Fields\/ColourPicker\/DetailView.tpl<\/code>: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script src=\"custom\/include\/SugarFields\/Fields\/ColourPicker\/js\/jqColorPicker.min.js\">&lt;\/script>\n{if strlen({{sugarvar key='value' string=true}}) &lt;= 0}\n    {assign var=\"value\" value={{sugarvar key='default_value' string=true}} }\n{else}\n    {assign var=\"value\" value={{sugarvar key='value' string=true}} }\n{\/if}\n&lt;input disabled=\"disabled\" type='text' name='{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{\/if}}'\n       id='{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{\/if}}'\n       size='{{$displayParams.size|default:30}}'\n       {{if isset($displayParams.maxlength)}}maxlength='{{$displayParams.maxlength}}'{{elseif isset($vardef.len)}}maxlength='{{$vardef.len}}'{{\/if}}\n       value='{$value}' title='{{$vardef.help}}' {{if !empty($tabindex)}} tabindex='{{$tabindex}}' {{\/if}}\n        {{if !empty($displayParams.accesskey)}} accesskey='{{$displayParams.accesskey}}' {{\/if}}\n        {{$displayParams.field}}>\n                            \/\/\n&lt;script>\n    {literal}\n    $(document).ready(function(){\n        $('#{\/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}\n        {{$displayParams.idName}}{{\/if}}{literal}').colorPicker();\n    });\n    {\/literal}\n&lt;\/script><\/code><\/pre>\n\n\n\n<p><strong>Step 6:<\/strong>  Add Edit View at&nbsp;<code>custom\/include\/SugarFields\/Fields\/ColourPicker\/EditView.tpl<\/code>: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script src=\"custom\/include\/SugarFields\/Fields\/ColourPicker\/js\/jqColorPicker.min.js\">&lt;\/script>\n{if strlen({{sugarvar key='value' string=true}}) &lt;= 0}\n    {assign var=\"value\" value={{sugarvar key='default_value' string=true}} }\n{else}\n    {assign var=\"value\" value={{sugarvar key='value' string=true}} }\n{\/if}\n&lt;input type='text' name='{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{\/if}}'\n       id='{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{\/if}}'\n       size='{{$displayParams.size|default:30}}'\n       {{if isset($displayParams.maxlength)}}maxlength='{{$displayParams.maxlength}}'{{elseif isset($vardef.len)}}maxlength='{{$vardef.len}}'{{\/if}}\n       value='{$value}' title='{{$vardef.help}}' {{if !empty($tabindex)}} tabindex='{{$tabindex}}' {{\/if}}\n        {{if !empty($displayParams.accesskey)}} accesskey='{{$displayParams.accesskey}}' {{\/if}}\n        {{$displayParams.field}}>\n                            \/\/\n&lt;script>\n    {literal}\n    $(document).ready(function(){\n        $('#{\/literal}{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}\n        {{$displayParams.idName}}{{\/if}}{literal}').colorPicker();\n    });\n    {\/literal}\n&lt;\/script><\/code><\/pre>\n\n\n\n<p> After a quick repair and rebuild (and assuming the field has been added to the views). <\/p>\n\n\n\n<p>You\u2019ll see the new field: <\/p>\n\n\n\n<ul class=\"wp-block-gallery aligncenter columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"40\" src=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/04ColourPicker.png\" alt=\"\" data-id=\"195\" data-link=\"https:\/\/www.techcrm.in\/blogs\/?attachment_id=195\" class=\"wp-image-195\"\/><\/figure><\/li><\/ul>\n\n\n\n<p>Hope this helps and feels like missing piece is just found!<\/p>\n\n\n\n<p>Feel free to drop your comments.<\/p>\n\n\n\n<p>Your valuable feedback means a lot.<\/p>\n\n\n\n<p>You can contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:contact@urdhva-tech.com\" target=\"_blank\">info@techcrm.in<\/a><\/p>\n\n\n\n<p>Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Like a lot of SuiteCRM the field types are customisable and you can add your own types of fields. This post will explain how to add a colour picker as a custom field type. Steps are as below, Setp 1: First off we need to add the option to studio to allow creating fields of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[43,44,12,13],"class_list":["post-193","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-custom-field","tag-custom-field-type","tag-sugarcrm","tag-suitecrm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Creating a custom field type in SuiteCRM - TechCRM<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating a custom field type in SuiteCRM - TechCRM\" \/>\n<meta property=\"og:description\" content=\"Like a lot of SuiteCRM the field types are customisable and you can add your own types of fields. This post will explain how to add a colour picker as a custom field type. Steps are as below, Setp 1: First off we need to add the option to studio to allow creating fields of [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-10T18:21:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:25:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png\" \/>\n<meta name=\"author\" content=\"Navin Rakhonde\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Navin Rakhonde\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/\",\"name\":\"Creating a custom field type in SuiteCRM - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png\",\"datePublished\":\"2019-09-10T18:21:43+00:00\",\"dateModified\":\"2020-09-08T09:25:34+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png\",\"contentUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SugarCRM\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Creating a custom field type in SuiteCRM\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/\",\"name\":\"TechCRM\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\",\"name\":\"Navin Rakhonde\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"caption\":\"Navin Rakhonde\"},\"sameAs\":[\"https:\/\/www.techcrm.in\/\"],\"url\":\"https:\/\/www.techcrm.in\/blogs\/author\/navin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating a custom field type in SuiteCRM - TechCRM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/","og_locale":"en_US","og_type":"article","og_title":"Creating a custom field type in SuiteCRM - TechCRM","og_description":"Like a lot of SuiteCRM the field types are customisable and you can add your own types of fields. This post will explain how to add a colour picker as a custom field type. Steps are as below, Setp 1: First off we need to add the option to studio to allow creating fields of [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/","og_site_name":"TechCRM","article_published_time":"2019-09-10T18:21:43+00:00","article_modified_time":"2020-09-08T09:25:34+00:00","og_image":[{"url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png"}],"author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/","url":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/","name":"Creating a custom field type in SuiteCRM - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage"},"image":{"@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage"},"thumbnailUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png","datePublished":"2019-09-10T18:21:43+00:00","dateModified":"2020-09-08T09:25:34+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#primaryimage","url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png","contentUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/09\/03ColourPickerStudio.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/creating-a-custom-field-type-in-suitecrm\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techcrm.in\/blogs\/"},{"@type":"ListItem","position":2,"name":"SugarCRM","item":"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/"},{"@type":"ListItem","position":3,"name":"Creating a custom field type in SuiteCRM"}]},{"@type":"WebSite","@id":"https:\/\/www.techcrm.in\/blogs\/#website","url":"https:\/\/www.techcrm.in\/blogs\/","name":"TechCRM","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc","name":"Navin Rakhonde","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","caption":"Navin Rakhonde"},"sameAs":["https:\/\/www.techcrm.in\/"],"url":"https:\/\/www.techcrm.in\/blogs\/author\/navin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/comments?post=193"}],"version-history":[{"count":2,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/193\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}