<?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>topic Using conditional statement in shell tasks with checkbox as custom option in HPE Morpheus Enterprise</title>
    <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/using-conditional-statement-in-shell-tasks-with-checkbox-as/m-p/7247555#M729</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Without if statement&lt;/STRONG&gt;&lt;BR /&gt;
In the example below, we have a shell script task with a variable ‘checkStatus’. The value of ‘checkStatus’ will be either &lt;STRONG&gt;‘on’&lt;/STRONG&gt; when checked, or &lt;STRONG&gt;‘off’&lt;/STRONG&gt; when unchecked.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= customOptions.cluster_checkbox %&amp;gt;"
echo "myVal = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Using if statement&lt;/STRONG&gt;&lt;BR /&gt;
But on the following task we are using an if statement to set the value of ‘checkStatus’. In this case when the checkbox is checked the value will be &lt;STRONG&gt;‘on’&lt;/STRONG&gt;. But if the checkbox is unchecked the value will not be empty string or ‘off’, but &lt;STRONG&gt;‘null’&lt;/STRONG&gt;.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= if (customOptions.cluster_checkbox == 'on') { 'on' } %&amp;gt;"
echo "checkStatus = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When using if statement as shown above, you must specify the value to return when the checkbox is unchecked. Otherwise, it will just return null. On the example below we are also including an &lt;STRONG&gt;‘else’&lt;/STRONG&gt; statement to return &lt;STRONG&gt;‘off’&lt;/STRONG&gt; when unchecked.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= if (customOptions.cluster_checkbox == 'on') { 'on' } else { 'off' }%&amp;gt;"
echo "checkStatus = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 Feb 2023 11:53:45 GMT</pubDate>
    <dc:creator />
    <dc:date>2023-02-21T11:53:45Z</dc:date>
    <item>
      <title>Using conditional statement in shell tasks with checkbox as custom option</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/using-conditional-statement-in-shell-tasks-with-checkbox-as/m-p/7247555#M729</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Without if statement&lt;/STRONG&gt;&lt;BR /&gt;
In the example below, we have a shell script task with a variable ‘checkStatus’. The value of ‘checkStatus’ will be either &lt;STRONG&gt;‘on’&lt;/STRONG&gt; when checked, or &lt;STRONG&gt;‘off’&lt;/STRONG&gt; when unchecked.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= customOptions.cluster_checkbox %&amp;gt;"
echo "myVal = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;Using if statement&lt;/STRONG&gt;&lt;BR /&gt;
But on the following task we are using an if statement to set the value of ‘checkStatus’. In this case when the checkbox is checked the value will be &lt;STRONG&gt;‘on’&lt;/STRONG&gt;. But if the checkbox is unchecked the value will not be empty string or ‘off’, but &lt;STRONG&gt;‘null’&lt;/STRONG&gt;.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= if (customOptions.cluster_checkbox == 'on') { 'on' } %&amp;gt;"
echo "checkStatus = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When using if statement as shown above, you must specify the value to return when the checkbox is unchecked. Otherwise, it will just return null. On the example below we are also including an &lt;STRONG&gt;‘else’&lt;/STRONG&gt; statement to return &lt;STRONG&gt;‘off’&lt;/STRONG&gt; when unchecked.&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;checkStatus="&amp;lt;%= if (customOptions.cluster_checkbox == 'on') { 'on' } else { 'off' }%&amp;gt;"
echo "checkStatus = $checkStatus"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2023 11:53:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/using-conditional-statement-in-shell-tasks-with-checkbox-as/m-p/7247555#M729</guid>
      <dc:creator />
      <dc:date>2023-02-21T11:53:45Z</dc:date>
    </item>
  </channel>
</rss>

