<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Reference additional JavaScript libraries to the code tree</title><link>https://www.aras.com/community/f/development/3511/reference-additional-javascript-libraries-to-the-code-tree</link><description>Hi,

I am using additional JavaScript libraries, and at this moment I am adding them manually on each form. Is there a way that I could referenced them inside the code tree in a way that they be available in all forms?</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Reference additional JavaScript libraries to the code tree</title><link>https://www.aras.com/community/thread/1164?ContentTypeID=1</link><pubDate>Wed, 03 Jan 2018 07:23:07 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b37afbac-60a9-4933-be56-d9b6b0aca935</guid><dc:creator>carstenw</dc:creator><description>I asked Rolf about this at ACE Europe and he kindly mailed me the following:

&amp;nbsp;

This is a sample how to create a JS library i.e. with your own utility functions to be used on every Form or other client side JS code,

&amp;nbsp;

NOTICE:  changes to the code tree are necessary !!!  You will have to redo these changes on every upgrade.

&amp;nbsp;

(1) Create a JS file with a class of your utility functions.  In this case we call it   &amp;quot;FormUtilities.js&amp;quot;.

&amp;nbsp;

Sample functions in FormUtilities.js could be:

&amp;nbsp;

// Library Class

FormUtilities = function () {

//variables

this.varibale_1 = &amp;quot;XX&amp;quot;;

&amp;nbsp;

};

&amp;nbsp;

// Library functions

FormUtilities.prototype.showFormFieldByPropName = function FormUtilities_showFormFieldByPropName(propName, show) {

var field = getFieldByName(propName);

if (field)

{

var visibility = show ? &amp;quot;visible&amp;quot; : &amp;quot;hidden&amp;quot;;

var display    = show ? &amp;quot;&amp;quot;        : &amp;quot;none&amp;quot;;

&amp;nbsp;

var fieldStyle = field.style;

fieldStyle.visibility = visibility;

fieldStyle.display    = display;

}

};

&amp;nbsp;

FormUtilities.prototype.showFormFieldByFieldName = function FormUtilities_showFormFieldByFieldName(fieldName, show) {

var field = document.getElementsByName(fieldName)[0];

if (field)

{

var visibility = show ? &amp;quot;visible&amp;quot; : &amp;quot;hidden&amp;quot;;

var display    = show ? &amp;quot;&amp;quot;        : &amp;quot;none&amp;quot;;

&amp;nbsp;

var fieldStyle = field.style;

fieldStyle.visibility = visibility;

fieldStyle.display    = display;

}

};

(2) copy this JS file to the code tree of your Aras Installation.

&amp;nbsp;

Go to folder …innovator/client/javascript

&amp;nbsp;

Add a folder for your library.. In this case we create a folder &amp;quot;Customer&amp;quot;  copy your JS file into this folder.

&amp;nbsp;

(3) register your JS file in several Aras config files  (make backup copies of files before you edit them !!!)

&amp;nbsp;

In your code tree edit file ... Innovator\Client\javascript\IncludeNamespaceConfig.xml

&amp;nbsp;

Find tag         &amp;lt;/JavaScriptNamespace&amp;gt;

&amp;nbsp;

Insert following row before this tag:

&amp;lt;class name=&amp;quot;/FormUtilities&amp;quot; src=&amp;quot;Customer\FormUtilities.js&amp;quot;/&amp;gt;

&amp;nbsp;

Save and close the file.

&amp;nbsp;

&amp;nbsp;

In your code tree edit file ... innovator\Client\Modules\aras.innovator.core.Form\Views\FormInstance.cshtml

&amp;nbsp;

Find tag            &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;@Url.ContentWithSalt(&amp;quot;~/javascript/include.aspx?classes=/dojo.js&amp;quot;)&amp;quot;

&amp;nbsp;

Insert following row before this tag:

&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;@Url.ContentWithSalt(&amp;quot;~/javascript/include.aspx?classes=/FormUtilities&amp;quot;)&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;

&amp;nbsp;

Save and close the file.

&amp;nbsp;

In your code tree edit file ... innovator\Client\Modules\aras.innovator.core.ItemWindow\Views\Shared\_Layout.cshtml

&amp;nbsp;

Find tag            &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;@Url.ContentWithSalt(&amp;quot;~/javascript/include.aspx?classes=/dojo.js&amp;quot;)&amp;quot;

&amp;nbsp;

Insert following row before this tag:

&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;@Url.ContentWithSalt(&amp;quot;~/javascript/include.aspx?classes=/FormUtilities&amp;quot;)&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;

&amp;nbsp;

Save and close the file.

&amp;nbsp;

&amp;nbsp;

(4) Use library function on a Form logic.

&amp;nbsp;

In this example we add a JS-Method to the &amp;quot;Part&amp;quot; form onto form event &amp;quot;onLoad&amp;quot;.

&amp;nbsp;

JS-Method  &amp;quot;testingFormUtilities&amp;quot;:

&amp;nbsp;

….

var fu = new FormUtilities();

&amp;nbsp;

fu.showFormFieldByPropName(&amp;quot;description&amp;quot;, false);

….

&amp;nbsp;

==&amp;gt; the effect now is that when you open a &amp;quot;Part&amp;quot; the description field will not be shown.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>