<?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: Using a Script Include, in a Widget in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029478#M686404</link>
    <description>&lt;P&gt;You should use a GlideAjax to call a Script Include from the client side. Some documentation about GlideAjax can be found&amp;nbsp;&lt;A title="GlideAjax" href="https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_reference/GlideAjax/concept/c_GlideAjaxAPI.html" target="_blank" rel="noopener noreferrer nofollow"&gt;here&lt;/A&gt;. And there is another helpful link which can be found&amp;nbsp;&lt;A title="GlideAjax example" href="https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=c44a07a9db5cdbc01dcaf3231f961941" target="_blank" rel="noopener noreferrer nofollow"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please mark helpful/correct if this answered your question.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 19:35:11 GMT</pubDate>
    <dc:creator>Matt Taylor - G</dc:creator>
    <dc:date>2019-08-05T19:35:11Z</dc:date>
    <item>
      <title>Using a Script Include, in a Widget</title>
      <link>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029477#M686403</link>
      <description>&lt;P&gt;Trying to access a script include from within a widget. Here's what I'm doing.&lt;/P&gt;
&lt;P&gt;[HTML]&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;div class="panel panel-default"&amp;gt;
  &amp;lt;div class="panel-body m-b-n"&amp;gt;

    &amp;lt;div class="wrapper-md row no-margin"&amp;gt;
      &amp;lt;form class="basic-form"&amp;gt;
        
	&amp;lt;p&amp;gt;
          &amp;lt;!-- Name&amp;lt;br/&amp;gt; --&amp;gt;
          &amp;lt;input type="text" ng-model="c.data.user_name" id="user_name" name="user_name" size="25" placeholder = "Name"/&amp;gt;
        &amp;lt;/p&amp;gt;

        &amp;lt;p&amp;gt;
          &amp;lt;!-- Email&amp;lt;br/&amp;gt; --&amp;gt;
          &amp;lt;input type="text" ng-model="c.data.user_email" id="user_email" name="user_email" size="25" placeholder = "Email"/&amp;gt;
        &amp;lt;/p&amp;gt;
        &amp;lt;p&amp;gt;
          &amp;lt;!-- Phone Number&amp;lt;br/&amp;gt; --&amp;gt;
          &amp;lt;input type="text" ng-model="c.data.user_phone" id="user_phone" name="user_phone" size="25" placeholder = "Phone"/&amp;gt;
        &amp;lt;/p&amp;gt;

        &amp;lt;p&amp;gt;
          &amp;lt;!-- Message&amp;lt;br/&amp;gt; --&amp;gt;
          &amp;lt;textarea name="user_message" ng-model="c.data.user_message" id="user_message" cols="40" rows="5" placeholder = "Message"&amp;gt;&amp;lt;/textarea&amp;gt;
        &amp;lt;/p&amp;gt;

      &amp;lt;/form&amp;gt;
      &amp;lt;div class="modal-footer"&amp;gt;
        &amp;lt;button type="submit" class="btn btn-primary" id="submit_popup" name="submit_popup"
                ng-click="c.submitData(user_name, user_email, user_phone, user_message);"&amp;gt;${Submit}&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt; &amp;lt;!-- button --&amp;gt;
    &amp;lt;/div&amp;gt; &amp;lt;!-- wrapper-md row --&amp;gt;

  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[Client]&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function(spUtil, $window) {
	/* widget controller */
	var c = this;

	c.submitData = function(){
		var redir = 'https://MY-INSTANCE.service-now.com/sp?id=REDIR';
		
		c.data.action = "addData";
		
		c.server.update().then(function(){
						
			c.data.action = undefined;
			c.data.user_name = "";
			c.data.user_email = "";
			c.data.user_phone = "";			
			c.data.user_message = "";
			
			// spUtil.addInfoMessage("Thank you for your submission.");
		 
		handleRedirect('REDIR-PLACE', redir);

		});

	}

	function handleRedirect(redirectTo, redirectUrl) {
		if (redirectUrl) {
			$window.location.href = redirectUrl;
			return;
		}
}

}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[SERVER]&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function() {

	data.stuff = [];


	if (input) {

		if (input.action == "addData") {
			data.stuff = input.stuff;
			
			// MY SCRIPT INCLUDE
			var checkThings = new ValidateThings();
			var emailValid = data.checkThings.isValidEmail(input.user_email);
			var phoneValid = data.checkThings.isValidPhone(input.user_phone);
			
			if(!phoneValid) {
				data.phoneCheck = false;	
			} else {
			    var user_phone = input.user_phone;
			}

			if(!emailValid){
				data.emailCheck = false;
			} else {
			    var user_email = input.user_email;
			}

			var user_name = input.user_name;
			var user_location = input.user_location;
			var user_message = input.user_message;
			var assign_group = 'My Group';
			var incident_type = 'Bob';
			
			//Generate Problem description using variables combined into one variable
			var message_concat = 'Name: ' + user_name + '\n' + 'Email: ' + user_email + '\n' + 'Phone: ' + user_phone + '\n' +  'Message' + '\n' + '--------------------------------------------------------------' + '\n' + user_message;
			var short_descr = 'Submitted by ' + user_name;

			gs.log('MY MESSAGE: ' + message_concat);	
			
			var requestBody = {};
			
			requestBody.assignment_group = assign_group;
			requestBody.u_type = incident_type;
			requestBody.short_description = short_descr;
			requestBody.u_job_description = message_concat;
			requestBody.description = "hello there moto";


			//Encode as JSON
			var rBody = new global.JSON().encode(requestBody);
			gs.log("MY BODY: " + rBody);


			//REST API to Create incident		
			var request = new sn_ws.RESTMessageV2();
			request.setEndpoint('https://MY-INSTANCE.service-now.com/api/now/table/incident');
			request.setHttpMethod('POST');

			//Eg. UserName="UserName", Password="password" for this code sample.
			var user = 'SOMEUSER';
			var password = 'SOMEPASSWORD';

			request.setBasicAuth(user,password);
			request.setRequestHeader("Accept","application/json");
			request.setRequestHeader('Content-Type','application/json');
			request.setRequestBody(rBody);
			var response = request.execute();
			gs.log(response.getBody());

		}

	}


})();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I'm back in the client context I want to pick up {data.phoneCheck, data.emailCheck} for some type of message on screen if validation fails. But I'm not sure the ValidateThings object is even being created on the server side.&lt;BR /&gt;&lt;BR /&gt;So do I just to a: c.data.phoneCheck, c.data.emailCheck to grab my {true|false} on the client side, and a...&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if(!c.data.phonecheck){
    spUtil.addInfoMessage('Please check your phone number formatting');
}

if(!c.data.emailcheck){
   spUtil.addInfoMessage('Please check your email formatting');
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't seem to get this to click for me.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:27:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029477#M686403</guid>
      <dc:creator>ericgilmore</dc:creator>
      <dc:date>2019-08-05T19:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Script Include, in a Widget</title>
      <link>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029478#M686404</link>
      <description>&lt;P&gt;You should use a GlideAjax to call a Script Include from the client side. Some documentation about GlideAjax can be found&amp;nbsp;&lt;A title="GlideAjax" href="https://docs.servicenow.com/bundle/london-application-development/page/app-store/dev_portal/API_reference/GlideAjax/concept/c_GlideAjaxAPI.html" target="_blank" rel="noopener noreferrer nofollow"&gt;here&lt;/A&gt;. And there is another helpful link which can be found&amp;nbsp;&lt;A title="GlideAjax example" href="https://community.servicenow.com/community?id=community_question&amp;amp;sys_id=c44a07a9db5cdbc01dcaf3231f961941" target="_blank" rel="noopener noreferrer nofollow"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please mark helpful/correct if this answered your question.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:35:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029478#M686404</guid>
      <dc:creator>Matt Taylor - G</dc:creator>
      <dc:date>2019-08-05T19:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using a Script Include, in a Widget</title>
      <link>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029479#M686405</link>
      <description>&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;//Lines changed
//var emailValid = checkThings.isValidEmail(input.user_email);
//var phoneValid = checkThings.isValidPhone(input.user_phone);
//var user_phone;
//var user_email;
			
(function() {

	data.stuff = [];


	if (input) {

		if (input.action == "addData") {
			data.stuff = input.stuff;
			
			// MY SCRIPT INCLUDE
			var checkThings = new ValidateThings();
			var emailValid = checkThings.isValidEmail(input.user_email);
			var phoneValid = checkThings.isValidPhone(input.user_phone);
			var user_phone;
			var user_email;
			
			if(!phoneValid) {
				data.phoneCheck = false;	
			} else {
			    user_phone = input.user_phone;
			}

			if(!emailValid){
				data.emailCheck = false;
			} else {
			    user_email = input.user_email;
			}

			var user_name = input.user_name;
			var user_location = input.user_location;
			var user_message = input.user_message;
			var assign_group = 'My Group';
			var incident_type = 'Bob';
			
			//Generate Problem description using variables combined into one variable
			var message_concat = 'Name: ' + user_name + '\n' + 'Email: ' + user_email + '\n' + 'Phone: ' + user_phone + '\n' +  'Message' + '\n' + '--------------------------------------------------------------' + '\n' + user_message;
			var short_descr = 'Submitted by ' + user_name;

			gs.log('MY MESSAGE: ' + message_concat);	
			
			var requestBody = {};
			
			requestBody.assignment_group = assign_group;
			requestBody.u_type = incident_type;
			requestBody.short_description = short_descr;
			requestBody.u_job_description = message_concat;
			requestBody.description = "hello there moto";


			//Encode as JSON
			var rBody = new global.JSON().encode(requestBody);
			gs.log("MY BODY: " + rBody);


			//REST API to Create incident		
			var request = new sn_ws.RESTMessageV2();
			request.setEndpoint('https://MY-INSTANCE.service-now.com/api/now/table/incident');
			request.setHttpMethod('POST');

			//Eg. UserName="UserName", Password="password" for this code sample.
			var user = 'SOMEUSER';
			var password = 'SOMEPASSWORD';

			request.setBasicAuth(user,password);
			request.setRequestHeader("Accept","application/json");
			request.setRequestHeader('Content-Type','application/json');
			request.setRequestBody(rBody);
			var response = request.execute();
			gs.log(response.getBody());

		}

	}


})();
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:40:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/using-a-script-include-in-a-widget/m-p/2029479#M686405</guid>
      <dc:creator>vkachineni</dc:creator>
      <dc:date>2019-08-05T19:40:16Z</dc:date>
    </item>
  </channel>
</rss>

