Not able to populate the sn record picker value in to the payload

JhansiN06297899
Kilo Contributor

I am creating a form where i take the input of user "assigned by" and i am able to get the user details and fill the user details but io am trying to insert that user in to results table i am not getting the output in the table i am using like this  <div class="manager-picker-container">
<label class="required">Manager on Duty</label>
<div class="aor-select-wrap">
<sn-record-picker
selected ="c.data.managerUser"
table="'sys_user'"
display-field="'name'"
value-field="'sys_id'"
search-fields="'name,email,first_name,last_name'"
default-query="'active=true'"
page-size="50"
placeholder="Select Manager on Duty"
show-add="false">
</sn-record-picker>
</div>
</div>

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@JhansiN06297899 

try like this and enhance

HTML:

<sn-record-picker 
  selected="c.data.managerUser"
  table="'sys_user'"
  display-field="'name'"
  value-field="'sys_id'"
  search-fields="'name,email,first_name,last_name'"
  default-query="'active=true'"
  page-size="50"
  placeholder="Select Manager on Duty"
  show-add="false">
</sn-record-picker>

<button ng-click="c.addManager()">Add to Results</button>

<table>
  <thead>
    <tr><th>Name</th><th>Email</th></tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in c.data.results">
      <td>{{user.name}}</td>
      <td>{{user.email}}</td>
    </tr>
  </tbody>
</table>

Client Controller:

c.data.results = [];
c.addManager = function() {
  // Assume c.data.managerUser contains sys_id
  // Fetch user details (can be via client-side call or server call)
  c.server.get({
    action: 'getUserDetails',
    sysId: c.data.managerUser
  }).then(function(response){
    c.data.results.push(response.data);
  });
};

Server:

if (input && input.action === 'getUserDetails') {
  var gr = new GlideRecord('sys_user');
  if (gr.get(input.sysId)) {
    answer = {
      name: gr.name.toString(),
      email: gr.email.toString()
    };
  }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@JhansiN06297899 

try like this and enhance

HTML:

<sn-record-picker 
  selected="c.data.managerUser"
  table="'sys_user'"
  display-field="'name'"
  value-field="'sys_id'"
  search-fields="'name,email,first_name,last_name'"
  default-query="'active=true'"
  page-size="50"
  placeholder="Select Manager on Duty"
  show-add="false">
</sn-record-picker>

<button ng-click="c.addManager()">Add to Results</button>

<table>
  <thead>
    <tr><th>Name</th><th>Email</th></tr>
  </thead>
  <tbody>
    <tr ng-repeat="user in c.data.results">
      <td>{{user.name}}</td>
      <td>{{user.email}}</td>
    </tr>
  </tbody>
</table>

Client Controller:

c.data.results = [];
c.addManager = function() {
  // Assume c.data.managerUser contains sys_id
  // Fetch user details (can be via client-side call or server call)
  c.server.get({
    action: 'getUserDetails',
    sysId: c.data.managerUser
  }).then(function(response){
    c.data.results.push(response.data);
  });
};

Server:

if (input && input.action === 'getUserDetails') {
  var gr = new GlideRecord('sys_user');
  if (gr.get(input.sysId)) {
    answer = {
      name: gr.name.toString(),
      email: gr.email.toString()
    };
  }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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