<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>POPULAR POST Archives - N2 Help &amp; Solutions</title>
	<atom:link href="https://n2.help/category/popular-post/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Community of independent digital experts</description>
	<lastBuildDate>Mon, 03 Nov 2025 12:21:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>How to use ChatGPT to generate ServiceNow JavaScript code</title>
		<link>https://n2.help/how-to-use-chatgpt-to-generate-servicenow-javascript-code/</link>
		
		<dc:creator><![CDATA[nadmin2]]></dc:creator>
		<pubDate>Mon, 03 Apr 2023 12:06:06 +0000</pubDate>
				<category><![CDATA[ESM]]></category>
		<category><![CDATA[POPULAR POST]]></category>
		<category><![CDATA[Servicenow]]></category>
		<guid isPermaLink="false">https://n2.help/?p=1438</guid>

					<description><![CDATA[<p>In this article, I will show you how I used ChatGPT to generate ServiceNow JavaScript code for a Business rule. This use case can be applied to other coding areas such as client scripts, script includes, jelly scripts, and scheduled jobs. If you are interested in the other integration possibilities of ChatGPT and ServiceNow, you [&#8230;]</p>
<p>The post <a href="https://n2.help/how-to-use-chatgpt-to-generate-servicenow-javascript-code/">How to use ChatGPT to generate ServiceNow JavaScript code</a> appeared first on <a href="https://n2.help">N2 Help &amp; Solutions</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this article, I will show you how I used ChatGPT to generate ServiceNow JavaScript code for a Business rule. This use case can be applied to other coding areas such as client scripts, script includes, jelly scripts, and scheduled jobs. If you are interested in the other integration possibilities of ChatGPT and ServiceNow, <a href="https://n2.help/6-ways-to-integrate-servicenow-with-chatgpt/" data-type="link" data-id="https://n2.help/6-ways-to-integrate-servicenow-with-chatgpt/">you can read this article</a>.</p>



<p>In the following use case, we will generate code to ensure that no change record is closed until all its related change tasks are closed. We will use the “name” field of the business rule record to define our coding requirement. For example:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>Generate ServiceNow business rule code that only allows change closure if all related change tasks are closed.</em></p>
</blockquote>



<p>Once the business rule is named and its conditions are updated, the integration will trigger the code generation in the “Script” field of the business rule’s “Advanced” tab.</p>



<p><strong>NOTE:</strong> You may need to adjust the generated code to meet your specific requirements. The more clear and precise your requirement is, the better the code generated by ChatGPT will be, and the less modification will be required.</p>



<h2 class="wp-block-heading">6 steps to Integrate ServiceNow with ChatGPT:</h2>



<h3 class="wp-block-heading">1. Generate API secret key</h3>



<p>Generate Secret <a href="https://platform.openai.com/api-keys" data-type="link" data-id="https://platform.openai.com/api-keys">API key from Open AI</a> Chat GTP application, which will be used for authentication in the next step.</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1024" height="295" src="https://n2.help/wp-content/uploads/2025/01/image-1.png" alt="" class="wp-image-1442"/></figure>



<h3 class="wp-block-heading">2. Create a rest message</h3>



<p>Create a REST message with end point as &gt; <strong>https://api.openai.com/v1/completions</strong></p>



<p><strong>Use the syntax :</strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>Authorization – Barear</em> &lt;your_token_key&gt;</p>
</blockquote>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p></p>
</blockquote>
</blockquote>



<p>In ServiceNow HTTP Request headers along with content type as application/json.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1047" height="612" src="https://n2.help/wp-content/uploads/2025/01/image-3.png" alt="" class="wp-image-1443"/></figure>



<h3 class="wp-block-heading">Create a “POST” method</h3>



<p>Create a “POST” Method as shown above with same end point and “HTTP Request headers”, In the “HTTP Query Parameters” pass the content in the below json format. You can copy/past this code:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>{<br>“model”: “text-davinci-003”,<br>“prompt”: “${question}”,<br>“max_tokens”: 1024,<br>“temperature”: 0<br>}</em></p>
</blockquote>



<figure class="wp-block-image size-full"><img decoding="async" width="1361" height="661" src="https://n2.help/wp-content/uploads/2025/01/image-4.png" alt="" class="wp-image-1444"/></figure>



<h3 class="wp-block-heading">Auto-generate variables</h3>



<p>Click on the ”Auto-generate variables” which will result in creation of a variable in the “variable substitutions” related list. Pass the value in the string format in the “Test value”.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1366" height="620" src="https://n2.help/wp-content/uploads/2025/01/image-5.png" alt="" class="wp-image-1445"/></figure>



<h3 class="wp-block-heading">5. Test and get HTTP status 200</h3>



<p>Click on “Test”. HTTP Status 200 indicates success, you will be able to see the code generated by ChatGPT in “Response” field as shown below.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1366" height="513" src="https://n2.help/wp-content/uploads/2025/01/image-6.png" alt="" class="wp-image-1446"/></figure>



<h3 class="wp-block-heading">6. Use “PreviewScript Usage”</h3>



<p>Use “PreviewScript Usage” UI action on the POST method to generate a javascript code which can be used to dynamically generate the code anywere needed. You can use JSON parser to prase the json response and extract the code as needed.</p>



<p><strong>Code :</strong></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><em>var r = new sn_ws.RESTMessageV2(‘GPT Magic’, ‘GET ANSWER’);<br>r.setStringParameterNoEscape(‘question’, ‘generate a servicenow business rule to allow to close the change only if all related change tasks are closed.’);<br>var response = r.execute();<br>var responseBody = response.getBody();<br>var str = JSON.parse(responseBody);<br>var script = str.choices[0].text;<br>gs.print(script);</em></p>
</blockquote>



<p>I have used the above script as business rule in a business rule table itself to generate code in advance tab, if the “name” field is updated with the code requirement as shown below.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1076" height="603" src="https://n2.help/wp-content/uploads/2025/01/image-7.png" alt="" class="wp-image-1447"/></figure>



<h2 class="wp-block-heading">Questions about ChatGPT integration with ServiceNow?</h2>



<p>In conclusion, using ChatGPT to generate ServiceNow JavaScript code is a powerful tool that can save time and effort. By following the steps outlined in this article, you can easily integrate ChatGPT with ServiceNow and generate code for various use cases. If you have any questions or need help with integrating ChatGPT with ServiceNow, <a href="https://n2.help/contact/" data-type="link" data-id="https://n2.help/contact/">don’t hesitate to contact us</a>. We’re here to help you maximize the benefits of this cutting-edge technology.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p></p>
</blockquote>



<p></p>
<p>The post <a href="https://n2.help/how-to-use-chatgpt-to-generate-servicenow-javascript-code/">How to use ChatGPT to generate ServiceNow JavaScript code</a> appeared first on <a href="https://n2.help">N2 Help &amp; Solutions</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
