<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Using shared  catalog client scripts in Community Central forum</title>
    <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503518#M6272</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a 'reliable' mechanism to allow 'shared' code between / among catalog client scripts in the same catalog item?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is, a client catalog script would load with the intent of being able to be called by another client catalog script in the same catalog item.&amp;nbsp; Presently using Yokohama (patch 10).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;John Spencer&lt;/P&gt;</description>
    <pubDate>Sun, 08 Mar 2026 03:36:23 GMT</pubDate>
    <dc:creator>John Spencer</dc:creator>
    <dc:date>2026-03-08T03:36:23Z</dc:date>
    <item>
      <title>Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503518#M6272</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a 'reliable' mechanism to allow 'shared' code between / among catalog client scripts in the same catalog item?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is, a client catalog script would load with the intent of being able to be called by another client catalog script in the same catalog item.&amp;nbsp; Presently using Yokohama (patch 10).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;John Spencer&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 03:36:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503518#M6272</guid>
      <dc:creator>John Spencer</dc:creator>
      <dc:date>2026-03-08T03:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503519#M6273</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351177"&gt;@John Spencer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could consider using a &lt;STRONG data-end="104" data-start="91"&gt;UI Script&lt;/STRONG&gt; to store the shared functions and then call those functions from your Catalog Client Scripts. This is a reliable way to reuse client-side code across multiple scripts and helps avoid duplicating logic.&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"If you found my answer helpful, please&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;like and mark it as an "accepted solution".&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;It helps future readers to locate the solution easily and supports the community!"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank You&lt;BR /&gt;Juhi Poddar&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 03:50:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503519#M6273</guid>
      <dc:creator>Juhi Poddar</dc:creator>
      <dc:date>2026-03-08T03:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503520#M6274</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/351177"&gt;@John Spencer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there is no available OOTB mechanism to control shared code between catalog client scripts.&lt;/P&gt;
&lt;P&gt;You need to handle this with your development experience and customer requirement and try to avoid conflicting scripts.&lt;/P&gt;
&lt;P&gt;Try to keep script in single onLoad always and you can write onChange script on variable based on requirement.&lt;BR /&gt;&lt;span class="lia-unicode-emoji" title=":light_bulb:"&gt;💡&lt;/span&gt; If my response helped, please mark it as correct &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt; and close the thread &lt;span class="lia-unicode-emoji" title=":locked:"&gt;🔒&lt;/span&gt;— this helps future readers find the solution faster! &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 03:51:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503520#M6274</guid>
      <dc:creator>Ankur Bawiskar</dc:creator>
      <dc:date>2026-03-08T03:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503525#M6275</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In ServiceNow, a&amp;nbsp;UI Script&amp;nbsp;is a &lt;STRONG&gt;reusable block of client-side JavaScript code&lt;/STRONG&gt;, similar to how a Script Include works for server-side code. They are used to promote code reusability and maintainability by centralizing common client-side functions like Client Scripts and Catalog Client Scripts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Ref:&amp;nbsp;&lt;A href="https://www.servicenow.com/docs/r/api-reference/scripts/c_UIScripts.html" target="_blank"&gt;https://www.servicenow.com/docs/r/api-reference/scripts/c_UIScripts.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;A href="https://www.servicenow.com/community/itsm-forum/what-is-ui-script-and-give-me-any-example-where-you-used-ui/td-p/925566" target="_blank"&gt;https://www.servicenow.com/community/itsm-forum/what-is-ui-script-and-give-me-any-example-where-you-used-ui/td-p/925566&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 04:18:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503525#M6275</guid>
      <dc:creator>Tanushree Maiti</dc:creator>
      <dc:date>2026-03-08T04:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503625#M6280</link>
      <description>&lt;P&gt;Ankur’s answer is the most practical. While there is almost always a way to accomplish something through customization (for example, calling another Catalog Client Script from a client script), this pattern is generally discouraged. If you find yourself needing it, there is usually a better out-of-the-box approach, or the underlying use case should be reconsidered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ask first: w&lt;STRONG&gt;hy is shared client logic required?&lt;/STRONG&gt; Often the goal is to avoid repeating the same logic, such as recalculations triggered by multiple &lt;FONT color="#FF0000"&gt;&lt;EM&gt;onChange&lt;/EM&gt;&lt;/FONT&gt; scripts.&lt;/P&gt;&lt;P&gt;If you truly need shared logic (e.g., calculations like infrastructure sizing for CPU or memory), a better approach is to implement the logic in a &lt;STRONG&gt;client-callable Script Include&lt;/STRONG&gt; and invoke it via GlideAjax. Keep logic in client scripts only when the behavior is purely UI-driven.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2026 14:12:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3503625#M6280</guid>
      <dc:creator>jeffreybell</dc:creator>
      <dc:date>2026-03-08T14:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using shared  catalog client scripts</title>
      <link>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3507640#M6363</link>
      <description>&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the approach of using the shared function in the onLoad script works fine. But it is not a documented approach as such, and I have seen it in this&amp;nbsp;&lt;A href="https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/td-p/3503518" target="_self"&gt;community post&lt;/A&gt;. The credit goes to them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create an onLoad script which stores the reusable shared code. Say something like this&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="javascript"&gt;function onLoad() {
}

/* Shared functions */
sayHello = function (msg) {
	alert('Hello ' + msg);
}​&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;Create an onChange script that calls the Shared functions&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   sayHello('John');
}​&lt;/LI-CODE&gt;&lt;P&gt;This should work in Native UI and Service Portal. I'm not sure about Workspaces and Mobile.&lt;/P&gt;&lt;P&gt;And also note, the shared functions must be written in the following format to make it work in Service Portal.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function_name = function () {
    // Do something
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree with Jeffrey Bell. The main reason we’d need this is when multiple onChange scripts share the same logic. However, I’ve also encountered forms that require certain validations before even initiating an Ajax call. It can be quite a tricky situation, I must say.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sometimes I wonder why wouldn't ServiceNow just implement&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;A mechanism to have form only reusable object (&lt;EM&gt;similar to g_scratchpad&lt;/EM&gt;) within Catalog form.&lt;/LI&gt;&lt;LI&gt;Allow variables that exist only on the Catalog Form, without being submitted or included in the Requested Item&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;They may seem so minor, but they significantly enhance the overall strength of the Form’s client-side capabilities.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Balu&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2026 12:45:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/community-central-forum/using-shared-catalog-client-scripts/m-p/3507640#M6363</guid>
      <dc:creator>balu_one</dc:creator>
      <dc:date>2026-03-13T12:45:21Z</dc:date>
    </item>
  </channel>
</rss>

