{"id":52665,"date":"2023-10-24T15:47:22","date_gmt":"2023-10-24T13:47:22","guid":{"rendered":"https:\/\/www.myscada.org\/?post_type=docs&#038;p=52665"},"modified":"2023-10-24T15:47:22","modified_gmt":"2023-10-24T13:47:22","password":"","slug":"using-components-in-view-scripts","status":"publish","type":"docs","link":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/","title":{"rendered":"Using components in view scripts"},"content":{"rendered":"<p style=\"text-align: justify;\">You can easily use the List box, combo box and text box in view scripts.<\/p>\n<p style=\"text-align: justify;\">We will start with a simple example showing how to use the combo box programmatically:<\/p>\n<p style=\"text-align: justify;\">1. We will create the combo box and add it to the view.<\/p>\n<p style=\"text-align: justify;\">2. We will create a button next to the combo box, on its press we will call view script function get Item.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg\" alt=\"getitem\" width=\"500\" height=\"173\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.2.jpg\" alt=\"onclick\" width=\"500\" height=\"312\" \/><\/p>\n<p style=\"text-align: justify;\">3. In getItem fuction, we will get value of selected component<\/p>\n<pre style=\"text-align: justify;\"><span style=\"color: #4baddd;\">var selItem = myscada.getSelectedItem('Comp29328366');<\/span><\/pre>\n<p style=\"text-align: justify;\"><span style=\"color: #000000;\"><strong>&#8216;Comp29328366&#8217; is an ID of our Combo box<\/strong><\/span>. You can find ID in properties window upon clicking on your Combo box.<\/p>\n<p style=\"text-align: justify;\">Once we get the selected item, we will show it by calling alert(selItem);<em><br \/>\n<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.3.jpg\" alt=\"8.3.3\" width=\"400\" height=\"109\" \/><\/p>\n<p style=\"text-align: justify;\">4. Now we will create a new button. On its press we will call view script function <em>setItem<\/em> where we will set item in combo box to second item.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.4.jpg\" alt=\"8.3.4\" width=\"500\" height=\"314\" \/><\/p>\n<h3><span style=\"color: #4baddd;\">Callback function example:<\/span><\/h3>\n<p style=\"text-align: justify;\">If you want to be notified, when user selects an item in the combo box or list box, or presses and enters into the text box, set up a callback function.<\/p>\n<p style=\"text-align: justify;\">1. Define your callback function in View Script<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.5.jpg\" alt=\"8.3.5\" width=\"350\" height=\"185\" \/><\/p>\n<p style=\"text-align: justify;\">As you can see, into your callback function, you will get 2 arguments, first is a selected item and second is an index of the selected item.<\/p>\n<p style=\"text-align: justify;\">2. Click on your component in view and fill in the callback function name<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.6.jpg\" alt=\"8.3.6\" width=\"500\" height=\"186\" \/><\/p>\n<p>3. When user selects an item, your callback function will be called<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.7.jpg\" alt=\"8.3.7\" width=\"300\" height=\"194\" \/><\/p>\n<h3><span style=\"color: #4baddd;\">Setting new values into Components Programmatically<\/span><\/h3>\n<p style=\"text-align: justify;\">You can easily change the items in your component programmatically. To do so, you can use function setItems:<\/p>\n<pre style=\"text-align: justify;\"><span style=\"color: #4baddd;\">var items = ['item 1','item 2'];<\/span>\n<span style=\"color: #4baddd;\">myscada.setItems('id',items);<\/span><\/pre>\n<h3><span style=\"color: #4baddd;\">Coloring items in List Box<\/span><\/h3>\n<p style=\"text-align: justify;\">List box allow you to fine tune appearance of each item by specifying the colors and bold face of the font. To do so, use function setItems. Passed items in array will not be strings but objects with additional properties. Simple Example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.8.jpg\" alt=\"8.3.8\" width=\"500\" height=\"236\" \/><\/p>\n<p>Will produce following output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.9.jpg\" alt=\"output\" width=\"244\" height=\"215\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can easily use the List box, combo box and text box in view scripts. We will start with a simple example showing how to use the combo box programmatically: 1. We will create the combo box and add it to the view. 2. We will create a button next to the combo box, on<a class=\"moretag excerpt orangelink\" href=\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":2555,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[325],"doc_tag":[],"class_list":["post-52665","docs","type-docs","status-publish","hentry","doc_category-mydesigner-v8"],"year_month":"2026-04","word_count":319,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Musilda","author_nicename":"musilda","author_url":"https:\/\/amitomation.cz\/en\/author\/musilda\/"},"doc_category_info":[{"term_name":"AMiTDesigner","term_url":"https:\/\/amitomation.cz\/en\/docs-category\/mydesigner-v8\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using components in view scripts - AMiT Automation<\/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:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using components in view scripts - AMiT Automation\" \/>\n<meta property=\"og:description\" content=\"You can easily use the List box, combo box and text box in view scripts. We will start with a simple example showing how to use the combo box programmatically: 1. We will create the combo box and add it to the view. 2. We will create a button next to the combo box, on[...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"AMiT Automation\" \/>\n<meta property=\"og:image\" content=\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\",\"url\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\",\"name\":\"Using components in view scripts - AMiT Automation\",\"isPartOf\":{\"@id\":\"https:\/\/amitomation.cz\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg\",\"datePublished\":\"2023-10-24T13:47:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage\",\"url\":\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg\",\"contentUrl\":\"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/amitomation.cz\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Documentation\",\"item\":\"https:\/\/amitomation.cz\/en\/documentation\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using components in view scripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/amitomation.cz\/en\/#website\",\"url\":\"https:\/\/amitomation.cz\/en\/\",\"name\":\"AMiT Automation\",\"description\":\"Czech manufacturer of Control Systems and Industrial Automation Electronics\",\"publisher\":{\"@id\":\"https:\/\/amitomation.cz\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/amitomation.cz\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/amitomation.cz\/en\/#organization\",\"name\":\"AMiT, spol. s r.o.\",\"url\":\"https:\/\/amitomation.cz\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/amitomation.cz\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/amitomation.cz\/wp-content\/uploads\/2017\/07\/amit_automation_100x42.gif\",\"contentUrl\":\"https:\/\/amitomation.cz\/wp-content\/uploads\/2017\/07\/amit_automation_100x42.gif\",\"width\":100,\"height\":42,\"caption\":\"AMiT, spol. s r.o.\"},\"image\":{\"@id\":\"https:\/\/amitomation.cz\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/organization\/10939938\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using components in view scripts - AMiT Automation","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:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/","og_locale":"en_US","og_type":"article","og_title":"Using components in view scripts - AMiT Automation","og_description":"You can easily use the List box, combo box and text box in view scripts. We will start with a simple example showing how to use the combo box programmatically: 1. We will create the combo box and add it to the view. 2. We will create a button next to the combo box, on[...]","og_url":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/","og_site_name":"AMiT Automation","og_image":[{"url":"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/","url":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/","name":"Using components in view scripts - AMiT Automation","isPartOf":{"@id":"https:\/\/amitomation.cz\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage"},"image":{"@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage"},"thumbnailUrl":"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg","datePublished":"2023-10-24T13:47:22+00:00","breadcrumb":{"@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#primaryimage","url":"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg","contentUrl":"http:\/\/myscada.org\/downloads\/manuals_image\/img_8.3.1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/amitomation.cz\/en\/documentation\/using-components-in-view-scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/amitomation.cz\/en\/"},{"@type":"ListItem","position":2,"name":"Documentation","item":"https:\/\/amitomation.cz\/en\/documentation\/"},{"@type":"ListItem","position":3,"name":"Using components in view scripts"}]},{"@type":"WebSite","@id":"https:\/\/amitomation.cz\/en\/#website","url":"https:\/\/amitomation.cz\/en\/","name":"AMiT Automation","description":"Czech manufacturer of Control Systems and Industrial Automation Electronics","publisher":{"@id":"https:\/\/amitomation.cz\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/amitomation.cz\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/amitomation.cz\/en\/#organization","name":"AMiT, spol. s r.o.","url":"https:\/\/amitomation.cz\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/amitomation.cz\/en\/#\/schema\/logo\/image\/","url":"https:\/\/amitomation.cz\/wp-content\/uploads\/2017\/07\/amit_automation_100x42.gif","contentUrl":"https:\/\/amitomation.cz\/wp-content\/uploads\/2017\/07\/amit_automation_100x42.gif","width":100,"height":42,"caption":"AMiT, spol. s r.o."},"image":{"@id":"https:\/\/amitomation.cz\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/organization\/10939938\/"]}]}},"_links":{"self":[{"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/docs\/52665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/users\/2555"}],"replies":[{"embeddable":true,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/comments?post=52665"}],"version-history":[{"count":1,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/docs\/52665\/revisions"}],"predecessor-version":[{"id":53676,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/docs\/52665\/revisions\/53676"}],"wp:attachment":[{"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/media?parent=52665"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/doc_category?post=52665"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/amitomation.cz\/en\/wp-json\/wp\/v2\/doc_tag?post=52665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}