<?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 How to detect toggle is enabled in UI builder page? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3070243#M1151800</link>
    <description>&lt;P&gt;I have created a settings page using UI builder. In that page I have a toggle and if the toggle is enabled then I want to trigger a scheduled job.&lt;/P&gt;&lt;P&gt;How we can check whether the toggle is enabled/disabled?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ajay&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 06:25:59 GMT</pubDate>
    <dc:creator>ajayraina14</dc:creator>
    <dc:date>2024-10-10T06:25:59Z</dc:date>
    <item>
      <title>How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3070243#M1151800</link>
      <description>&lt;P&gt;I have created a settings page using UI builder. In that page I have a toggle and if the toggle is enabled then I want to trigger a scheduled job.&lt;/P&gt;&lt;P&gt;How we can check whether the toggle is enabled/disabled?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ajay&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 06:25:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3070243#M1151800</guid>
      <dc:creator>ajayraina14</dc:creator>
      <dc:date>2024-10-10T06:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3070893#M1151990</link>
      <description>&lt;P&gt;One way to do this is to:&lt;BR /&gt;1. set up a boolean state variable such as toggleState&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-10 at 10.40.13 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/394243i545C3F65514EE179/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-10 at 10.40.13 AM.png" alt="Screenshot 2024-10-10 at 10.40.13 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;2. Bind the checked property to your state variable&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-10 at 10.40.23 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/394244iBF3D42545A64537F/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-10 at 10.40.23 AM.png" alt="Screenshot 2024-10-10 at 10.40.23 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;3. Update the state variable when the toggle changes&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-10 at 10.40.54 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/394245i7440803E4FEFC190/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-10 at 10.40.54 AM.png" alt="Screenshot 2024-10-10 at 10.40.54 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;4. you can then access the state variable later such as in this script I wrote when a button is clicked&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-10 at 10.46.24 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/394246i33A9192B78ED8A07/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-10 at 10.46.24 AM.png" alt="Screenshot 2024-10-10 at 10.46.24 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 14:46:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3070893#M1151990</guid>
      <dc:creator>Kevin83</dc:creator>
      <dc:date>2024-10-10T14:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3071402#M1152150</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/198475"&gt;@Kevin83&lt;/a&gt;&amp;nbsp; Thanks for the reply&lt;/P&gt;&lt;P&gt;I followed the steps but in the log it is always showing as false.&lt;/P&gt;&lt;P&gt;Can you please confirm if its giving correct value at your end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Ajay&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 06:56:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3071402#M1152150</guid>
      <dc:creator>ajayraina14</dc:creator>
      <dc:date>2024-10-11T06:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3071821#M1152266</link>
      <description>&lt;P&gt;Yes I checked it on my end and it is logging the value correctly&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-11 at 10.01.01 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/394479i53AD83520E776329/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-11 at 10.01.01 AM.png" alt="Screenshot 2024-10-11 at 10.01.01 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 14:01:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3071821#M1152266</guid>
      <dc:creator>Kevin83</dc:creator>
      <dc:date>2024-10-11T14:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3073227#M1152658</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/198475"&gt;@Kevin83&lt;/a&gt;&amp;nbsp; Below is the configuration which I have done, The only difference is that I want to trigger the toggle not with the button, the toggle on/off should be triggered by the toggle itself. Below are the screenshots:&lt;/P&gt;&lt;P&gt;The value is not changing when toggle is changed to on/off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 15:07:08 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3073227#M1152658</guid>
      <dc:creator>ajayraina14</dc:creator>
      <dc:date>2024-10-14T15:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to detect toggle is enabled in UI builder page?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3074243#M1152953</link>
      <description>&lt;P&gt;The event handlers associated with the toggle do not run in sequence, so it is possible your script runs before the state is updated.&lt;BR /&gt;&lt;BR /&gt;If you want to you reference the toggle value and update state all in one script something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-10-15 at 9.26.21 AM.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/395084i9576202152009628/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-10-15 at 9.26.21 AM.png" alt="Screenshot 2024-10-15 at 9.26.21 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;/**
* &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/2144"&gt;@Param&lt;/a&gt; {params} params
* &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/2144"&gt;@Param&lt;/a&gt; {api} params.api
* &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/2144"&gt;@Param&lt;/a&gt; {any} params.event
* &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/2144"&gt;@Param&lt;/a&gt; {any} params.imports
* &lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/2144"&gt;@Param&lt;/a&gt; {ApiHelpers} params.helpers
*/
function handler({api, event, helpers, imports}) {
    if (event.payload.value) { //toggle set to true
        console.log('enable job');
    } else { // toggle set to true
        console.log('disable job');
    }

    api.setState("toggleState", event.payload.value);
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case you may not need the state variable at all. The purpose of the state variable original was to do record the value of the toggle for later use by the button click, but it sounds like you want to take immediate action based on the toggle being clicked&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 13:30:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-detect-toggle-is-enabled-in-ui-builder-page/m-p/3074243#M1152953</guid>
      <dc:creator>Kevin83</dc:creator>
      <dc:date>2024-10-15T13:30:10Z</dc:date>
    </item>
  </channel>
</rss>

