{"id":96,"date":"2020-04-14T21:01:06","date_gmt":"2020-04-14T21:01:06","guid":{"rendered":"https:\/\/dxhelpdev.wpengine.com\/?post_type=epkb_post_type_1&#038;p=96"},"modified":"2020-08-05T18:54:29","modified_gmt":"2020-08-05T18:54:29","slug":"add-a-custom-script","status":"publish","type":"epkb_post_type_1","link":"https:\/\/dxhelp.scytec.com\/?epkb_post_type_1=add-a-custom-script","title":{"rendered":"Add a Custom Script"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Script Source can be to used to get data from a file, a database, or some other \u2018non standard\u2019 format. The script source will be treated like any other polling source, DataXchange will run the script on the polling interval set. The script will do whatever it is scripted to do to retrieve and parse data and populate variables that can then be used in DataXchange expressions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding a Custom Script Variable<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to create a valid Custom Script you need to create a new script variable. Go to <strong>DataXchange \u2192 Variable \u2192 Script<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"157\" height=\"229\" src=\"https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/06\/variable_script.png\" alt=\"\" class=\"wp-image-1151\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Once there, you will need to <strong>Add<\/strong> a new name and description for Source Variable. It is a good idea to have the name resemble the functionality of the written script.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"223\" src=\"https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/new_script.png\" alt=\"\" class=\"wp-image-1230\" srcset=\"https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/new_script.png 520w, https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/new_script-300x129.png 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Next you will need to create a communication method to the C# written script for the equipment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This can be done under the <strong>DataXchange<\/strong>&nbsp;tab, select the machine that you would like to configure and then click&nbsp;<strong>Communication<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1166\" height=\"406\" src=\"https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/communication_select.png\" alt=\"\" class=\"wp-image-1231\" srcset=\"https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/communication_select.png 1166w, https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/communication_select-300x104.png 300w, https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/communication_select-1024x357.png 1024w, https:\/\/dxhelp.scytec.com\/wp-content\/uploads\/2020\/07\/communication_select-768x267.png 768w\" sizes=\"auto, (max-width: 1166px) 100vw, 1166px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you will need to create a connection string to the C# written script within DataXchange. Click&nbsp;<strong>Add<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dx1.scytec.com\/help\/Images\/image1460187087.jpg\" alt=\"\" width=\"418\" height=\"96\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The custom script communicates as a data source only. From the Communication Role drop down select&nbsp;<strong>Source<\/strong> and for the Communication Type select&nbsp;<strong>Script<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dx1.scytec.com\/help\/Images\/image1278302132.jpg\" alt=\"\" width=\"362\" height=\"273\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You will then need to designate the <strong>Script Path<\/strong> to the location where the C# script is located. You can do this by selecting the <strong>Browse<\/strong> button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dx1.scytec.com\/help\/Images\/image1917855619.jpg\" alt=\"\" width=\"729\" height=\"164\"\/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the script has been selected you are ready to go. Once the Custom Script is used within an expression it will run the C# script you have written and return the desired value back.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Script Source can be to used to get data from a file, a database, or some other \u2018non standard\u2019 format. The script source will be treated like any other polling source, DataXchange will run the script on the polling interval set. The script will do whatever it is scripted to do to retrieve and parse [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"epkb_post_type_1_category":[46,36],"epkb_post_type_1_tag":[],"class_list":["post-96","epkb_post_type_1","type-epkb_post_type_1","status-publish","hentry","epkb_post_type_1_category-engineers","epkb_post_type_1_category-tutorials-expressions"],"_links":{"self":[{"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=\/wp\/v2\/epkb_post_type_1\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=\/wp\/v2\/epkb_post_type_1"}],"about":[{"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=\/wp\/v2\/types\/epkb_post_type_1"}],"author":[{"embeddable":true,"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":0,"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=\/wp\/v2\/epkb_post_type_1\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"epkb_post_type_1_category","embeddable":true,"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=%2Fwp%2Fv2%2Fepkb_post_type_1_category&post=96"},{"taxonomy":"epkb_post_type_1_tag","embeddable":true,"href":"https:\/\/dxhelp.scytec.com\/index.php?rest_route=%2Fwp%2Fv2%2Fepkb_post_type_1_tag&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}