<?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 How to send data from Client controller to Server side? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235677#M887661</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am a newbie to Service Portal.&lt;/P&gt;
&lt;P&gt;I have to create a page on which there are 2 dropdowns and 1 button.&lt;/P&gt;
&lt;P&gt;In the first drop-down, there are tables which &lt;STRONG&gt;extend the Task table&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;In the second drop-down, there are &lt;STRONG&gt;options(xls,docx)&lt;/STRONG&gt; in which &lt;STRONG&gt;format&lt;/STRONG&gt; user wants to &lt;STRONG&gt;download&lt;/STRONG&gt; the file.&lt;/P&gt;
&lt;P&gt;On click of a button, a user should get the &lt;STRONG&gt;file downloaded&lt;/STRONG&gt; with the 'list of column labels and names of the table choose&amp;nbsp;from first drop-down and add/insert the data into the (xls,docx) file'.&lt;/P&gt;
&lt;P&gt;My &lt;STRONG&gt;questions&lt;/STRONG&gt;&amp;nbsp;are:&lt;/P&gt;
&lt;P&gt;1. How to send the chosen table to server from client OR is there any other alternative to get all the columns of the table at client side?&lt;/P&gt;
&lt;P&gt;2. How to download a (docs,xls) file on click of a button with the column labels and names in it?&lt;/P&gt;
&lt;P&gt;Please find below what I have coded.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;HTML Template:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"/&amp;gt;
  &amp;lt;title&amp;gt;Green Folder&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;div class="form-group" &amp;gt;
        &amp;lt;select class="form-control" id="sel1" ng-model="optionText" ng-options="value for value in data.tables"&amp;gt;
          &amp;lt;option value="" disabled selected hidden&amp;gt;Select Table&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="form-group" &amp;gt;
        &amp;lt;select class="form-control" id="format"&amp;gt;
          &amp;lt;option value="" disabled selected hidden&amp;gt;Select Format&amp;lt;/option&amp;gt;
          &amp;lt;option value="xls"&amp;gt;xls&amp;lt;/option&amp;gt;
          &amp;lt;option value="docx"&amp;gt;docx&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="container"&amp;gt;
        &amp;lt;button type="submit" class="btn btn-default" ng-click="c.getMergeFields();"&amp;gt;Get Merge Fields&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Client Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function() {
  /* widget controller */
  var c = this;
	var optionText = c.data.tables;
	console.log("Option Text: " + optionText);
	
	c.getMergeFields = function(){
			var tableName= document.getElementById('sel1').value
		console.log("Table name: " + tableName);
		
		c.server.getmFields(tableName).then(function(resp){
			var getfields = resp.data.mFields;
		});
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Server Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	data.tables = getExtendTables();
	function getExtendTables(){
		//To fetch tables those extends Task table
		gs.include('TableUtils');
		
		var table = new global.TableUtils("task");
		var tableList = table.getAllExtensions();
		tableList = tableList.toString();
		
		gs.info("tableList of type " + typeof tableList + " == " + tableList);

		tableList = tableList.slice(1,-1);
		gs.info("Slicing of tableList of type: " + typeof tableList + " here: " + tableList);
		var arr = tableList.split(",");
		gs.info("Arr: " + arr);
		arr.sort();
		return arr;
	}
	
	//To fetch column labels and name of table selected by user
	 if(input){
		data.mFields = getmFields(input.tableName);
		gs.info("mFields: " + mFields);
	} 
	function getmFields(tableName){
		 gs.info("Input: " + tableName);
		var gr = new GlideRecord(tableName);
		gr.initialize();
    gr.query();
		gr.next();
		
		var elements = gr.getElements();
		var element;
		var result = [];
		for (var i=0; i&amp;lt;elements.length; i++) {
			element = elements[i];
			result[i]=element.getLabel();
    }		   
		result.sort();
		 gs.info("Result: " + result);
		return result; 
	 }
	 
})();


	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any better approach or best practice for this?&lt;/P&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Tue, 04 Dec 2018 07:34:28 GMT</pubDate>
    <dc:creator>NikitaAgarwal</dc:creator>
    <dc:date>2018-12-04T07:34:28Z</dc:date>
    <item>
      <title>How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235677#M887661</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am a newbie to Service Portal.&lt;/P&gt;
&lt;P&gt;I have to create a page on which there are 2 dropdowns and 1 button.&lt;/P&gt;
&lt;P&gt;In the first drop-down, there are tables which &lt;STRONG&gt;extend the Task table&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;In the second drop-down, there are &lt;STRONG&gt;options(xls,docx)&lt;/STRONG&gt; in which &lt;STRONG&gt;format&lt;/STRONG&gt; user wants to &lt;STRONG&gt;download&lt;/STRONG&gt; the file.&lt;/P&gt;
&lt;P&gt;On click of a button, a user should get the &lt;STRONG&gt;file downloaded&lt;/STRONG&gt; with the 'list of column labels and names of the table choose&amp;nbsp;from first drop-down and add/insert the data into the (xls,docx) file'.&lt;/P&gt;
&lt;P&gt;My &lt;STRONG&gt;questions&lt;/STRONG&gt;&amp;nbsp;are:&lt;/P&gt;
&lt;P&gt;1. How to send the chosen table to server from client OR is there any other alternative to get all the columns of the table at client side?&lt;/P&gt;
&lt;P&gt;2. How to download a (docs,xls) file on click of a button with the column labels and names in it?&lt;/P&gt;
&lt;P&gt;Please find below what I have coded.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;HTML Template:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"/&amp;gt;
  &amp;lt;title&amp;gt;Green Folder&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;div class="form-group" &amp;gt;
        &amp;lt;select class="form-control" id="sel1" ng-model="optionText" ng-options="value for value in data.tables"&amp;gt;
          &amp;lt;option value="" disabled selected hidden&amp;gt;Select Table&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="form-group" &amp;gt;
        &amp;lt;select class="form-control" id="format"&amp;gt;
          &amp;lt;option value="" disabled selected hidden&amp;gt;Select Format&amp;lt;/option&amp;gt;
          &amp;lt;option value="xls"&amp;gt;xls&amp;lt;/option&amp;gt;
          &amp;lt;option value="docx"&amp;gt;docx&amp;lt;/option&amp;gt;
        &amp;lt;/select&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="container"&amp;gt;
        &amp;lt;button type="submit" class="btn btn-default" ng-click="c.getMergeFields();"&amp;gt;Get Merge Fields&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Client Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function() {
  /* widget controller */
  var c = this;
	var optionText = c.data.tables;
	console.log("Option Text: " + optionText);
	
	c.getMergeFields = function(){
			var tableName= document.getElementById('sel1').value
		console.log("Table name: " + tableName);
		
		c.server.getmFields(tableName).then(function(resp){
			var getfields = resp.data.mFields;
		});
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Server Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	data.tables = getExtendTables();
	function getExtendTables(){
		//To fetch tables those extends Task table
		gs.include('TableUtils');
		
		var table = new global.TableUtils("task");
		var tableList = table.getAllExtensions();
		tableList = tableList.toString();
		
		gs.info("tableList of type " + typeof tableList + " == " + tableList);

		tableList = tableList.slice(1,-1);
		gs.info("Slicing of tableList of type: " + typeof tableList + " here: " + tableList);
		var arr = tableList.split(",");
		gs.info("Arr: " + arr);
		arr.sort();
		return arr;
	}
	
	//To fetch column labels and name of table selected by user
	 if(input){
		data.mFields = getmFields(input.tableName);
		gs.info("mFields: " + mFields);
	} 
	function getmFields(tableName){
		 gs.info("Input: " + tableName);
		var gr = new GlideRecord(tableName);
		gr.initialize();
    gr.query();
		gr.next();
		
		var elements = gr.getElements();
		var element;
		var result = [];
		for (var i=0; i&amp;lt;elements.length; i++) {
			element = elements[i];
			result[i]=element.getLabel();
    }		   
		result.sort();
		 gs.info("Result: " + result);
		return result; 
	 }
	 
})();


	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there any better approach or best practice for this?&lt;/P&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 07:34:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235677#M887661</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-04T07:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235678#M887662</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using DOM manipulations is not a best practice. Instead you can pass your values from ng-model and then from client scrip to server you can do something like this :-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function($scope) {     


       var c = this;


   c.data.abc='Value';


       c.func_name= function() {


               c.server.update();





       }


}



Server side you can use


if(input)


{


gs.log(input.abc);


}

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 07:42:19 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235678#M887662</guid>
      <dc:creator>Omkar Mone</dc:creator>
      <dc:date>2018-12-04T07:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235679#M887663</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You can use c.server.update to send the data to server as mentioned below.&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;function($scope) { &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; var c = this;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; c.data.&lt;STRONG&gt;abc&lt;/STRONG&gt;='Any Name';&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; c.update = function() {&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c.server.update().then(function (response) {&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; c.data = {};&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; })&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="ng-scope"&gt; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Server side you can use&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;if(input)&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;gs.log(input.&lt;STRONG&gt;abc);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;else&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;{&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;//Code for initial load&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="ng-scope"&gt;&amp;nbsp;&lt;/SPAN&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt; Mark &lt;STRONG&gt;correct &lt;/STRONG&gt;or &lt;STRONG&gt;helpful &lt;/STRONG&gt;if it helps you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm Regards,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Raj patel&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 07:42:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235679#M887663</guid>
      <dc:creator>RajP79032538207</dc:creator>
      <dc:date>2018-12-04T07:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235680#M887664</link>
      <description>&lt;P&gt;Hi Nikita,&lt;/P&gt;
&lt;P&gt;To download the file you can build your button with href tag like below&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;&amp;lt;button href="/sys_attachment.do?sys_id="+sys_id_of_attachment&amp;gt;Download&amp;lt;button&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To send data do server or vice verca&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;Client side
$scope.data.abc ="hello";
$scope.server.update().then(function(response){
console.log(response.xyz);
});

server side
if(input.abc){
data.xyz = "hi";
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Async Server call : $scope.server.update();&lt;/P&gt;
&lt;P&gt;Sync call :&amp;nbsp;&amp;nbsp;$scope.server.update().then(function(response){&lt;/P&gt;
&lt;P&gt;});&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2018 07:45:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235680#M887664</guid>
      <dc:creator>rahulpandey</dc:creator>
      <dc:date>2018-12-04T07:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235681#M887665</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;I tried this but I am getting an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see my updated code below.&lt;/P&gt;
&lt;P&gt;I have pointed error in server script as comments beside &lt;STRONG&gt;gr.query();&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Client Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;function() {
  /* widget controller */
  var c = this;
	var $scope = this;
//List of tables stored
	var optionText = c.data.tables;
	console.log("Option Text: " + optionText);
	

	$scope.getMergeFields = function(){
//Fetch the selected table value from HTML using ng-model
		$scope.data.tables = $scope.options;
		console.log("Scope table name:" + $scope.data.tables);
//Call to server
		$scope.server.update();
	}
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Server Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if(input){
	gs.log("Input: " + input.tables);//Getting user selected table.
	var gr = new GlideRecord(input.tables);
	gr.initialize();

	gr.query(); //Error at this point.It says " org.mozilla.javascript.EvaluatorException: GlideRecord.addQuery() - invalid table name: incident (sp_widget.418270c1db0623005f151fc768961924.script; line 29)"

	gr.next();
		
	var elements = gr.getElements();
	var element;
	var result = [];
	for (var i=0; i&amp;lt;elements.length; i++) {
		element = elements[i];
		result[i]=element.getLabel();
	}		   
	result.sort();
	gs.info("Result: " + result);
		return result;
}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 07:36:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235681#M887665</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-05T07:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235682#M887666</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Do you want to get the labels of a tables ? is it your requirement ? if yes, please use below code&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;      if(input)
{data.fields = $sp.getListColumns(input.tables, input.view ||'default');
	data.fields_array = data.fields.split(',');
	var grForLabels = new GlideRecord(data.table);
	for (var i in data.fields_array) {
		console.log('going here');
		var field = data.fields_array[i];
		var ge = grForLabels.getElement(field);
		if (ge == null)
			continue;
		var dataobj = {};
		dataobj.value = field.toString();
		dataobj.text = ge.getLabel().toString();
		columnArray.push(dataobj);
	}
	data.columnDetails = columnArray;
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 09:36:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235682#M887666</guid>
      <dc:creator>rahulpandey</dc:creator>
      <dc:date>2018-12-05T09:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235683#M887667</link>
      <description>&lt;P&gt;No, I have already fetched table names.&lt;/P&gt;
&lt;P&gt;I want column labels and column names of the table.&lt;/P&gt;
&lt;P&gt;For eg.: Consider &lt;STRONG&gt;Incident Table&lt;/STRONG&gt;, which has Assigned to column with a &lt;STRONG&gt;label as "Assigned to"&lt;/STRONG&gt; and &lt;STRONG&gt;name as "assigned_to"&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;Likewise, I need all the columns of the selected table.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:35:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235683#M887667</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-05T11:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235684#M887668</link>
      <description>&lt;P&gt;Hi Nikita,&lt;/P&gt;
&lt;P&gt;The code I gave you exactly does the same thing. Please see below screenshot and updated code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if(input){
		columnArray = [];
data.fields = $sp.getListColumns(input.table, 'default');
	data.fields_array = data.fields.split(',');
	var grForLabels = new GlideRecord(input.table);
	for (var i in data.fields_array) {
		console.log('going here');
		var field = data.fields_array[i];
		var ge = grForLabels.getElement(field);
		if (ge == null)
			continue;
		var dataobj = {};
		dataobj.value = field.toString();
		dataobj.text = ge.getLabel().toString();
		columnArray.push(dataobj);
	}
	data.columnDetails = columnArray;
	}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/79110i855C8B1DE15F2399/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:48:36 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235684#M887668</guid>
      <dc:creator>rahulpandey</dc:creator>
      <dc:date>2018-12-05T11:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235685#M887669</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code is working fine when tested with manually entering the table name as you did in the screenshot. But it is not working when I update the table name with &lt;STRONG&gt;input.tables&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;Neither I got value for the data.fields nor fields_array and others also. As no fields are&amp;nbsp;fetched, its giving error at line 9 (according to your screenshot).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error at line 9: &lt;SPAN class="ng-binding"&gt;org.mozilla.javascript.EvaluatorException: GlideRecord.getElement() - invalid table name: incident (sp_widget.418270c1db0623005f151fc768961924.script; &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 13:56:09 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235685#M887669</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-05T13:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235686#M887670</link>
      <description>&lt;P&gt;Hi Nikita,&lt;/P&gt;
&lt;P&gt;there seems to be an issue, whether input.tables are returning table or not.&lt;/P&gt;
&lt;P&gt;instead of directly using input.tables, fir store into a variable like&lt;/P&gt;
&lt;P&gt;var Inouttable = input,tables; and try the code.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 20:21:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235686#M887670</guid>
      <dc:creator>rahulpandey</dc:creator>
      <dc:date>2018-12-05T20:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235687#M887671</link>
      <description>&lt;P&gt;1) To answer the title of your post: How to send data from Client controller to Server side?&lt;BR /&gt;Normally these two methods on "this" or "c "are used:&lt;/P&gt;
&lt;UL&gt;&lt;LI&gt;.server.update() - Automatically sends this.data to the server as input&lt;/LI&gt;&lt;LI&gt;.server.get() - Sends a custom input object&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;A third option is via url&lt;BR /&gt;&lt;BR /&gt;2) Looking at some of the threads in this post I'm not sure if you're just trying to download an attachment that is of xls/docx type or if you're trying to just download a xls/docx file based on give table/record information. In the below screencast, is this what you're trying to accomplish?&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;https://youtu.be/4_pTCOmZc1k&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;IFRAME id="video_tinymce" style="width: 225%; height: 480px;" src="https://www.youtube.com/embed/4_pTCOmZc1k"&gt;&lt;/IFRAME&gt;&lt;/P&gt;
&lt;P&gt;This may not be exactly what you're looking for but I think it has the same concepts where there is input and then it's sent to the server to return some information in order to download a file based on the input. This isn't downloading an attachment though. In this video the widget is downloading either an excel file of the all the incident lists, then a file of a list of incidents based on an encoded query and then finally downloads a single incident record based on the incident number.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This is just a basic MOC up of what I think what is discussed in this thread. Let me know if this is what you're looking for and I'll post the setup.&lt;/P&gt;
&lt;P&gt;&lt;IFRAME src="https://www.youtube.com/embed/4_pTCOmZc1k" width="560" height="315"&gt;&lt;/IFRAME&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 03:42:35 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235687#M887671</guid>
      <dc:creator>ChrisBurks</dc:creator>
      <dc:date>2018-12-06T03:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235688#M887672</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input.tables is returning selected value as expected.&lt;/P&gt;
&lt;P&gt;Yes, I did try this, but nothing worked out. I am getting the value printed correctly in logs.&lt;/P&gt;
&lt;P&gt;I think methods are not able to understand the value from input.tables or something is missing in it.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 04:18:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235688#M887672</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-06T04:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235689#M887673</link>
      <description>&lt;P&gt;Hi Rahul,&lt;/P&gt;
&lt;P&gt;Your code worked out.&lt;/P&gt;
&lt;P&gt;There was a space in input.tables value like " incident" instead of "incident", due to which it was not processing.&lt;/P&gt;
&lt;P&gt;Thank you so much for the help! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In future, if anyone comes up for the same issue below is updated code:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Server Script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;if(input){
	columnArray = [];
	data.fields = $sp.getListColumns(input.tables, 'default');
	data.fields_array = data.fields.split(',');
	
	var grForLabels = new GlideRecord(input.tables);
	dataobj = function(){
		this.value="";
		this.text="";
		this.toString = function(){
			return "Data: " + this.value + ": " + this.text;
		};
	}
		
	for (var i in data.fields_array) {
		var field = data.fields_array[i];
		var ge = grForLabels.getElement(field);
		if (ge == null)
			continue;
		var col = new dataobj();
		col.value = field.toString();
		col.text = ge.getLabel().toString();
		columnArray.push(col);
	}
	data.columnDetails = columnArray;
	}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;Client script:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;$scope.getMergeFields = function(){
		$scope.data.tables = $scope.options;
		$scope.server.update().then(function(){
			for(var f in $scope.data.columnDetails){
				console.log("F: " + $scope.data.columnDetails[f].toString() + " : " + $scope.data.columnDetails[f].text + " : " + $scope.data.columnDetails[f].value);
			}
		})
	}&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Dec 2018 08:32:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235689#M887673</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-06T08:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235690#M887674</link>
      <description>&lt;P&gt;Hi Chris,&lt;/P&gt;
&lt;P&gt;Thank you for the response! My issue to fetch column names and labels has been resolved now.&lt;/P&gt;
&lt;P&gt;I am looking forward to inserting the fetched data into docx, xls file and get it to download as per user selection.&lt;/P&gt;
&lt;P&gt;I check out the video link, it is somewhat similar to what the requirement is. I have mentioned my requirement below.&lt;/P&gt;
&lt;P&gt;My requirement is Onclick of a button the column names and labels should be inserted in the document and it should be downloaded(xls, docx file which depends on user selection) directly.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Dec 2018 10:25:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/2235690#M887674</guid>
      <dc:creator>NikitaAgarwal</dc:creator>
      <dc:date>2018-12-06T10:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to send data from Client controller to Server side?</title>
      <link>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/3073015#M1152575</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;SPAN&gt;Mega Sage,&amp;nbsp; Do you give training on service portal as well or know any one ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 11:44:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/how-to-send-data-from-client-controller-to-server-side/m-p/3073015#M1152575</guid>
      <dc:creator>ANUSHREEY</dc:creator>
      <dc:date>2024-10-14T11:44:23Z</dc:date>
    </item>
  </channel>
</rss>

