passing value from server script to client/html?

Prem13
Tera Contributor

Unable to retrieve the value which is being passed from server script

Server script:-

data.name = '';

data.email = '';

// get current user email
var uemail; 
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.query();
if(usr.next())
{
data.email = usr.email;
}

client script:-

var temp = c.data.email;
	alert(JSON.stringify(c.data.email));

 

Alert returns empty { }

 

1 ACCEPTED SOLUTION

Assumption - you are using Service Portal. If this is standard lists/forms, please clarify. The approach is totally different.

Note: Always assume (because it's true) that fields are objects. If you want the value, use getValue() or getDisplayValue().

Server script:

data.email = '';

var usr = new GlideRecord('sys_user');
if (usr.get(gs.getUserID()) {
  data.email = usr.getValue('email');
  if (data.email == '') {
    gs.error('This user has no email');
  }
} else {
  gs.error('Unable to read current user record');
}

Client script:

console.log('Email=' + c.data.email);

View solution in original post

6 REPLIES 6

im using the piece of code in widget server and client

Mike Patel
Tera Sage

try

Server script:-

data.name = '';

data.email = '';

// get current user email
var uemail; 
var usr = new GlideRecord('sys_user');
if(usr.get(gs.getUserID())){
data.email = usr.email.toString();
}


client script:-

var temp = c.data.email;
alert(temp);