I want to fetch the details from user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 05:38 AM
I have created the one page in the widget there are three personas they are hire new, new role and new company if select the one persona then one dropdown should be display in that in have give few roles now when i select any persona and role then if i click on the next button the selected details are first name and last name should be populated in another page, here I fetching the users data from user table i have developed the but I'm not able to fetch the details, below I have pasted my code.
html
----------------
<div class="persona-container">
<div class="card p-2" >
<h4 style="margin-left:20px;margin-bottom:1opx;">Select Persona</h4>
<p style="margin-left:20px;margin-bottom:1opx;"><strong>Select appropriate Persona to create a Plan</strong></p>
<div class="persona-option" ng-repeat="p in personas">
<div class="d-flex justify-content-between align-items-center p-2 border rounded mb-2"
ng-class="{'selected':selectedPersona === p}">
<div class="d-flex align-items-center">
<i class ="fa" ng-class="selectedPersona === p ? 'fa-check-circle text-success':'fa-circle-thin'"></i>
<span class="ml-2">{{p}}</span>
</div>
<button class="btn btn-outline-primary btn-sm" ng-click=" toggleSelection(p)">{{selectedPersona === p ? 'Remove'
: 'Select'}}</button>
</div>
</div>
<div ng-if="selectedPersona === 'New to Ralliant'" style="margin-left:15px;" class="mt-2">
<label for="ralliantDropdown"><strong>Select Ralliant Option:</strong>
</label>
<select id ="ralliantDropdown" class="form-control mt-1" style="width:50%;" style="margin-left:20px;" ng-model="selectedRalliantOption">
<option value="" disabled selected>Select Role</option>
<option value="Ralliant Option 1">OpCo Role</option>
<option value="Ralliant Option 2">Ralliant Corporate Role</option>
<!--<option value="Ralliant Option 3">New role 3</option>-->
</select>
</div>
<div ng-if="selectedPersona === 'New to OpCo'" class="mt-2" style="margin-left:20px;">
<label for="opcoDropdown"><strong>Select OpCo Option:</strong>
</label>
<select id ="opcoDropdown" class="form-control mt-1" style="width:50%;" style="margin-left:20px;" ng-model="selectedOpcoOption">
<option value="" disabled selected>Select Role</option>
<option value="OpCo Option 1">New role 1</option>
<option value="OpCo Option 2">New role 2</option>
<option value="OpCo Option 3">New role 3</option>
</select>
</div>
<button class="btn btn-primary btn-block mt-3 btn-imm " ng-click="c.redirectToPage()" ng-disabled="!selectedPersona">
Next</button>
</div>
client
---------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 05:45 AM
@GPavanKumK To troubleshoot this issue, you will have to add log statements in your script include to check below things
1) Is script include getting called?
2) print "user.getEncodedQuery()" after doing query to user table to know what was the query sent to user table.
3) Print the result.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 06:07 AM
your Glideajax parameters should be consistent althroughout.
I see some sysparam instead of sysparm. Maybe thats why its failing.
Also, you dont need GlideAjax to call backend when using widgets. Just simply use server.update or server.get .
More details here: https://www.servicenow.com/community/developer-articles/get-server-data-in-widget-client-controller/...
Please accept solution if this helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 06:36 AM
try this
Script Include:
var GetUserDetailsByPersona = Class.create();
GetUserDetailsByPersona.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUser: function() {
var persona = this.getParameter('sysparam_persona');
var role = this.getParameter('sysparam_role');
var user = new GlideRecord('sys_user');
if (persona == "New to Ralliant" || persona == "New to OpCo") {
user.addQuery('active', true);
// Optionally filter by role if provided
if (role) {
user.addQuery('title', role); // Change 'title' to the relevant field
}
}
user.setLimit(1);
user.query();
if (user.next()) {
var result = {
first_name: user.first_name.toString(),
last_name: user.last_name.toString(),
employee_id: user.employee_number.toString(),
};
return JSON.stringify(result);
}
return JSON.stringify({});
}
});
You are passing a sysparam_role from the client, but not using it in your Script Include. If you want to filter users based on role, add a query for roles.
var role = this.getParameter('sysparam_role');
if (role) {
user.addQuery('roles.name', role); // Adjust as per your role field structure
}
Corrected client controller script:
$scope.fetchUserDetails = function(callback) {
// Set selectedRole based on persona
$scope.selectedRole = $scope.selectedRalliantOption || $scope.selectedOpcoOption || "";
var immper = new GlideAjax('GetUserDetailsByPersona');
immper.addParam('sysparm_name', 'getUser');
immper.addParam('sysparam_persona', $scope.selectedPersona);
immper.addParam('sysparam_role', $scope.selectedRole);
immper.getXMLAnswer(function(response) {
try {
var userData = JSON.parse(response);
$rootScope.selectedUser = userData;
if (callback) callback();
} catch (e) {
console.error("Error parsing user data:", e);
}
});
};
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader