<?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 Can we trigger outbound REST using catalog client script ? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489232#M970727</link>
    <description>&lt;P&gt;we need to trigger an out Bound rest API while catalog item field change (asset field )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="String_0-1677394560050.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/243042iDDEFC3FD4B0FCF4A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="String_0-1677394560050.png" alt="String_0-1677394560050.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;outbound Json:&lt;/P&gt;&lt;P&gt;“Catalog”: {&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;“Asset”:”XYZ”,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;“Type:”outbound”,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when user changes the asset field than we have capture the asset values and &amp;nbsp;trigger the out Bound .&lt;/P&gt;&lt;P&gt;So Can please suggest the best practices to achieve&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2023 07:02:54 GMT</pubDate>
    <dc:creator>String</dc:creator>
    <dc:date>2023-02-26T07:02:54Z</dc:date>
    <item>
      <title>Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489232#M970727</link>
      <description>&lt;P&gt;we need to trigger an out Bound rest API while catalog item field change (asset field )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="String_0-1677394560050.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/243042iDDEFC3FD4B0FCF4A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="String_0-1677394560050.png" alt="String_0-1677394560050.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;outbound Json:&lt;/P&gt;&lt;P&gt;“Catalog”: {&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;“Asset”:”XYZ”,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;“Type:”outbound”,&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when user changes the asset field than we have capture the asset values and &amp;nbsp;trigger the out Bound .&lt;/P&gt;&lt;P&gt;So Can please suggest the best practices to achieve&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 07:02:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489232#M970727</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2023-02-26T07:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489267#M970739</link>
      <description>&lt;P&gt;You can certainly build a Script Include which the Client Script will call, which would have the Script Include itself calling the REST API and then passing the results back down to the Client.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;You would do this through a "combination client script" leveraging GlideAjax which includes both Client executable code and server executable code.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please mark as correct answer if this solves your issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 08:52:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489267#M970739</guid>
      <dc:creator>Aavi</dc:creator>
      <dc:date>2023-02-26T08:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489280#M970742</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/64273"&gt;@Aavi&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your quick reply, can you share sample code if possible ?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 11:10:26 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489280#M970742</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2023-02-26T11:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489327#M970760</link>
      <description>&lt;P&gt;Try the following steps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Navigate to System Web services -&amp;gt; Outbound -&amp;gt; Rest Messages, open the Http methods for the api which created and scroll down to related links to click "Preview Script usage" and copy the script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Go to script include --&amp;gt;New&lt;BR /&gt;Name: integrationClientUtilities&lt;BR /&gt;Client callable: true&lt;BR /&gt;Accessible from: All application scopes&lt;BR /&gt;Script:&lt;BR /&gt;&lt;BR /&gt;var integrationClientUtilities = Class.create();&lt;BR /&gt;integrationClientUtilities.prototype = {&lt;BR /&gt;initialize: function() {},&lt;/P&gt;&lt;P&gt;apicall: function() {&lt;BR /&gt;var asset = this.getParameter('sysparm_asset'); //value from client&lt;BR /&gt;var asset_name; //get the asset display name&lt;BR /&gt;var get_asset = new GlideRecord('alm_asset');&lt;BR /&gt;if (get_asset.get(asset)) {&lt;BR /&gt;asset_name = get_asset.display_name.toString();&lt;BR /&gt;}&lt;BR /&gt;//Paste the script which copied in Step 2&lt;BR /&gt;try {&lt;BR /&gt;var r = new sn_ws.RESTMessageV2('Integration', 'method post');&lt;BR /&gt;r.setStringParameterNoEscape('Asset', asset_name);&lt;BR /&gt;r.setStringParameterNoEscape('Type', 'outbound');&lt;BR /&gt;var response = r.execute();&lt;BR /&gt;var responseBody = response.getBody();&lt;BR /&gt;var httpStatus = response.getStatusCode();&lt;BR /&gt;gs.info("header " + httpStatus);&lt;BR /&gt;gs.info("body " + responseBody);&lt;BR /&gt;if (httpStatus == 200)&lt;BR /&gt;return 'success'; //In case if you want store the output in the form, you should parse response body&lt;/P&gt;&lt;P&gt;} catch (ex) {&lt;BR /&gt;var message = ex.message;&lt;BR /&gt;}&lt;BR /&gt;},&lt;/P&gt;&lt;P&gt;type: 'integrationClientUtilities'&lt;BR /&gt;});&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Open the catalog item to create new catalog client script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name: onChange Asset call API&lt;BR /&gt;Type: onChange&lt;BR /&gt;UI Type: All&lt;BR /&gt;Variable Name: Asset&lt;BR /&gt;Script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function onChange(control, oldValue, newValue, isLoading) {&lt;BR /&gt;if (isLoading || newValue == '') {&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;var gaAJAX = new GlideAjax('integrationClientUtilities'); //Script include name&lt;BR /&gt;gaAJAX.addParam('sysparm_name', 'apicall'); //Function name&lt;BR /&gt;gaAJAX.addParam('sysparm_asset', g_form.getValue('asset')); //Pass the asset value to server side, make sure the variable name is correct&lt;BR /&gt;gaAJAX.getXMLAnswer(function(answer) {&lt;BR /&gt;if (answer == 'success')&lt;BR /&gt;g_form.addInfoMessage('API call success');&lt;BR /&gt;else&lt;BR /&gt;g_form.addErrorMessage('API call got failed')&lt;BR /&gt;';&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Faizeal.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 14:10:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489327#M970760</guid>
      <dc:creator>Faizeal Mohamed</dc:creator>
      <dc:date>2023-02-26T14:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489382#M970784</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/111146"&gt;@Faizeal Mohamed&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perfect ,thanks for the details explanation .&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 18:01:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489382#M970784</guid>
      <dc:creator>String</dc:creator>
      <dc:date>2023-02-26T18:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can we trigger outbound REST using catalog client script ?</title>
      <link>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489400#M970792</link>
      <description>&lt;P&gt;Yes, you can trigger an outbound REST API call using a Catalog Client Script in ServiceNow.&lt;/P&gt;&lt;P&gt;A Catalog Client Script is a script that runs on the client-side (i.e. in the user's web browser)&lt;BR /&gt;&lt;BR /&gt;Here is another example:.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/*To trigger an outbound REST API call using a Catalog Client Script, you can use the XMLHttpRequest object or the fetch API to send an HTTP request to the desired API endpoint. Here's an example of how to use fetch to send an outbound REST API call from a Catalog Client Script:*/

javascript
Copy code
function onSubmit() {
    var myData = {
        // Data to send to the API endpoint
        // ...
    };
    fetch('https://example.com/api/endpoint', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(myData)
    })
    .then(response =&amp;gt; response.json())
    .then(data =&amp;gt; {
        // Handle the API response data
        // ...
    })
    .catch(error =&amp;gt; {
        // Handle the API error
        // ...
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 18:34:43 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/can-we-trigger-outbound-rest-using-catalog-client-script/m-p/2489400#M970792</guid>
      <dc:creator>raphaelcrv</dc:creator>
      <dc:date>2023-02-26T18:34:43Z</dc:date>
    </item>
  </channel>
</rss>

