how to pass client side input to server side in ServiceNow portal Widget

DB1
Tera Contributor

Hello All,

 

I have client side and server side scripting and I am trying to pass the input from client to server (script attached below).

I do get the first info message however not the second one. Need help on the same to pass the sysid of firstname from client to Server

Client:

 

	c.openexistingUserform=function(){  

		c.n={
			"firstname" :'',
			"busiphone" : '',
			"email1": '',
			"city1": ''		
		}			
		console.log("openexistingUserform" ,c.n);	
		c.data.action = 'addphUser';	
		c.server.update();
			
		document.getElementById("addexUserForm").style.display = "block";

	}	

 

I get the following output from the console

 

  1. busiphone: "(555) 555-0004"
  2. city1: ""
  3. email1: "abraham.lincoln@example.com"
  4. firstname: {value: 'a8f98bb0eb32010045e1a5115206fe3a', displayValue: 'Abraham Lincoln'}
  5. [[Prototype]]: Object

Server

 

 

if(input&&input.action=='addphUser')
	{
		gs.addInfoMessage("addphUser");
		var graddexuser2 = new GlideRecord('sys_user');
		graddexuser2.addQuery('sys_id',input.firstname);
		graddexuser2.query();
		if(graddexuser2.next())
		{
			gs.addInfoMessage("User " +graddexuser2.user_name);
			//data.existingUser.push({email:graddexuser2.email.toString(),busphone:graddexuser2.phone.toString()});
		}
	}

 

 

 

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

Hello @DB1 ,

can you replace input.firstname with  

input.n.firstname

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

are you sure the value you got is working correct?

check this

Communicating between the Client Script and the Server Script of a widget 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@DB1 

update as this and check once

graddexuser2.addQuery('first_name',input.n.fistname.value);

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar  
 I'm facing issue here when same code I'm using and Running in Global scope it is working fine  
But when same code in running  & Implementing  in Scoped Application  then this code is not working and not showing the output in Console on server side 

HTML Code
<form>
  <input type="text" name="chkRow" ng-model="c.data.half_day" />
  <input type="submit" value="Submit" ng-click="c.update()">
</form>

Client Side Script
api.controller = function () {
  var c = this;  c.data.half_day = 'ABC';  c.update = function () {
    c.data.action = 'Test';    c.server.update().then(function (response) {
      console.log(response);
    });
  }
};


Server Side Code
(function () {
  if (input && input.action === 'Test') {
    console.log(input.half_day);
  }
})();

 I'm also trying to used gs.info() , gs.log() on server side
Thanks & Regard
Abhijeet Burghate