<?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 Re: How to convert variable 'single line text' in an integer? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152880#M809806</link>
    <description>&lt;P&gt;If you decide to use the &lt;SPAN style="font-family: courier new,courier;"&gt;parseInt()&lt;/SPAN&gt; function, best practice is to specify the second parameter for radix, which is 10 for the decimal system. You might end up with unexpected results if you omit it, as it says in &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt" title="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt"&gt;parseInt() - JavaScript | MDN&lt;/A&gt;:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If &lt;VAR&gt;radix&lt;/VAR&gt; is &lt;STRONG&gt;undefined&lt;/STRONG&gt; or 0 (or absent), JavaScript assumes the following:&lt;/P&gt;&lt;BR /&gt;&lt;UL&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with "0x" or "0X", &lt;VAR&gt;radix&lt;/VAR&gt; is 16 (hexadecimal) and the remainder of the string is parsed.&lt;/LI&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with "0", &lt;VAR&gt;radix&lt;/VAR&gt; is eight (octal) or 10 (decimal). &amp;nbsp; Exactly which radix is chosen is implementation-dependent. &amp;nbsp; ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. &amp;nbsp; For this reason &lt;STRONG&gt;always specify a radix when using &lt;STRONG&gt;parseInt&lt;/STRONG&gt;&lt;/STRONG&gt;.&lt;/LI&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with any other value, the radix is 10 (decimal).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If the first character cannot be converted to a number, &lt;STRONG&gt;parseInt&lt;/STRONG&gt; returns &lt;STRONG&gt;NaN&lt;/STRONG&gt;.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;Please feel free to connect, follow, mark helpful / answer, like, endorse.&lt;/EM&gt;&lt;/P&gt;&lt;BR /&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="width: 172px;"&gt;John Chun, &lt;SPAN style="font-size: 8pt;"&gt;PhD PMP&lt;/SPAN&gt; &lt;A href="http://linkedin.com/in/DrJohnChun"&gt;&lt;IMG alt="see John's LinkedIn profile" class="image-2 jive-image" src="http://megaicons.net/static/img/icons_sizes/182/456/16/linkedin-icon.png" style="height: auto; vertical-align: -13px;" title="see John's LinkedIn profile" /&gt;&lt;/A&gt;&lt;P&gt;&lt;A href="http://snowaid.com/"&gt;&lt;IMG alt="visit snowaid" class="image-1 jive-image" src="http://snowaid.com/images/signature.png" style="height: auto; margin-top: -9px;" title="visit snowaid" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A _jive_internal="true" href="https://www.servicenow.com/people/drjohnchun/content"&gt;&lt;IMG alt="ServiceNow Advocate" class="image-3 jive-image" src="http://snowaid.com/images/sn_advocate_135x48.png" style="margin-top: -3px;" /&gt;&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 16 May 2017 22:40:58 GMT</pubDate>
    <dc:creator>drjohnchun</dc:creator>
    <dc:date>2017-05-16T22:40:58Z</dc:date>
    <item>
      <title>How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152875#M809801</link>
      <description>&lt;P&gt;Hi ServiceNow Community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've a variable type 'single line text' and I'd like convert this in a integer value, for exampe:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var number=g_form.getValue('u_variable_number');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (number &amp;gt; 10)&lt;/P&gt;&lt;P&gt;number ++&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2017 16:52:27 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152875#M809801</guid>
      <dc:creator>davide_fais</dc:creator>
      <dc:date>2017-05-16T16:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152876#M809802</link>
      <description>&lt;P&gt;Hello Davide,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;You can use the &lt;CODE&gt;parseInt("");&lt;/CODE&gt; function to have a string return an integer&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;For example &lt;/P&gt;&lt;BR /&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14949542273088592 jive_text_macro" data-renderedposition="113_8_1192_96" jivemacro_uid="_14949542273088592" modifiedtitle="true"&gt;&lt;P&gt;var number = g_form.getValue('u_variable_number');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;var number = parseInt(number);&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;if(number &amp;gt; 10) {&lt;/P&gt;&lt;BR /&gt;&lt;P&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; number++;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;}&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2017 17:00:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152876#M809802</guid>
      <dc:creator>Patrick Fedigan</dc:creator>
      <dc:date>2017-05-16T17:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152877#M809803</link>
      <description>&lt;P&gt;Try this one&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;var number=g_form.getIntValue('u_variable_number');&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;if (number &amp;gt; 10)&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;number ++&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;etc&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 16 May 2017 17:03:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152877#M809803</guid>
      <dc:creator>BALAJI40</dc:creator>
      <dc:date>2017-05-16T17:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152878#M809804</link>
      <description>&lt;P&gt;Hi Davide,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Just to modify the code,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;OL class="dp-c" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; list-style-position: initial; list-style-image: initial; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; background-color: inherit; font-size: 9pt !important;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt; val= g_form.getValue(&lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; background-color: inherit; font-size: 9pt !important;"&gt;'u_variable_number'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt;); &amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; background-color: inherit; font-size: 9pt !important;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt; number = parseInt(val); &amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt; &amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; background-color: inherit; font-size: 9pt !important;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt;(number &amp;gt; &lt;/SPAN&gt;&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; background-color: inherit; font-size: 9pt !important;"&gt;10&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; background-color: inherit; font-size: 9pt !important;"&gt;) { &amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; number++; &amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;} &amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;Should be used&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;Shariq&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; background-color: inherit; font-size: 9pt !important;"&gt;mark helpful if it helps&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 16 May 2017 17:28:30 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152878#M809804</guid>
      <dc:creator>Sharique Azim</dc:creator>
      <dc:date>2017-05-16T17:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152879#M809805</link>
      <description>&lt;P&gt;converting a single line text to an integer is generally a bad idea.. when you find an A for example is that the number 10 &amp;lt;in base 16&amp;gt; or is it the letter A? .. hard to tell and harder to program around.. while the solutions given will work i would strongly suggest you retire that field from the form by unchecking active and add a NEW integer field that you can use for this purpose...&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;then, if required, write a background script to back-fill this field from the existing single line text field.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 16 May 2017 21:55:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152879#M809805</guid>
      <dc:creator>randrews</dc:creator>
      <dc:date>2017-05-16T21:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert variable 'single line text' in an integer?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152880#M809806</link>
      <description>&lt;P&gt;If you decide to use the &lt;SPAN style="font-family: courier new,courier;"&gt;parseInt()&lt;/SPAN&gt; function, best practice is to specify the second parameter for radix, which is 10 for the decimal system. You might end up with unexpected results if you omit it, as it says in &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt" title="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt"&gt;parseInt() - JavaScript | MDN&lt;/A&gt;:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;If &lt;VAR&gt;radix&lt;/VAR&gt; is &lt;STRONG&gt;undefined&lt;/STRONG&gt; or 0 (or absent), JavaScript assumes the following:&lt;/P&gt;&lt;BR /&gt;&lt;UL&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with "0x" or "0X", &lt;VAR&gt;radix&lt;/VAR&gt; is 16 (hexadecimal) and the remainder of the string is parsed.&lt;/LI&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with "0", &lt;VAR&gt;radix&lt;/VAR&gt; is eight (octal) or 10 (decimal). &amp;nbsp; Exactly which radix is chosen is implementation-dependent. &amp;nbsp; ECMAScript 5 specifies that 10 (decimal) is used, but not all browsers support this yet. &amp;nbsp; For this reason &lt;STRONG&gt;always specify a radix when using &lt;STRONG&gt;parseInt&lt;/STRONG&gt;&lt;/STRONG&gt;.&lt;/LI&gt;&lt;LI&gt;If the input &lt;STRONG&gt;string&lt;/STRONG&gt; begins with any other value, the radix is 10 (decimal).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If the first character cannot be converted to a number, &lt;STRONG&gt;parseInt&lt;/STRONG&gt; returns &lt;STRONG&gt;NaN&lt;/STRONG&gt;.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;EM&gt;Please feel free to connect, follow, mark helpful / answer, like, endorse.&lt;/EM&gt;&lt;/P&gt;&lt;BR /&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="width: 172px;"&gt;John Chun, &lt;SPAN style="font-size: 8pt;"&gt;PhD PMP&lt;/SPAN&gt; &lt;A href="http://linkedin.com/in/DrJohnChun"&gt;&lt;IMG alt="see John's LinkedIn profile" class="image-2 jive-image" src="http://megaicons.net/static/img/icons_sizes/182/456/16/linkedin-icon.png" style="height: auto; vertical-align: -13px;" title="see John's LinkedIn profile" /&gt;&lt;/A&gt;&lt;P&gt;&lt;A href="http://snowaid.com/"&gt;&lt;IMG alt="visit snowaid" class="image-1 jive-image" src="http://snowaid.com/images/signature.png" style="height: auto; margin-top: -9px;" title="visit snowaid" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;A _jive_internal="true" href="https://www.servicenow.com/people/drjohnchun/content"&gt;&lt;IMG alt="ServiceNow Advocate" class="image-3 jive-image" src="http://snowaid.com/images/sn_advocate_135x48.png" style="margin-top: -3px;" /&gt;&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 16 May 2017 22:40:58 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-convert-variable-single-line-text-in-an-integer/m-p/2152880#M809806</guid>
      <dc:creator>drjohnchun</dc:creator>
      <dc:date>2017-05-16T22:40:58Z</dc:date>
    </item>
  </channel>
</rss>

