I want to fetch the details from user table

GPavanKumK
Tera Contributor

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.

 

 

client

---------------

api.controller = function($scope, $rootScope, $timeout) {
 
    $scope.personas = ["New to Ralliant", "New to OpCo", "New to Role"];
    $scope.selectedPersona = $rootScope.selectedPersona || "";
 
    $scope.toggleSelection = function(persona) {
        if ($scope.selectedPersona === persona) {
            $scope.selectedPersona = "";
            $rootScope.selectedPersona = "";
        } else {
            $scope.selectedPersona = persona;
            $rootScope.selectedPersona = persona;
        }
    };
 
    $scope.proceed = function() {
        $rootScope.selectedPersona = $scope.selectedPersona;
        $rootScope.showLeaderForm = true;
    };
 
    $scope.fetchUserDetails = function(callback) {
        var immper = new GlideAjax('GetUserDetailsByPersona');
        immper.addParam('sysparm_name', 'getUser');
        immper.addParam('sysparm_persona', $scope.selectedPersona);
        immper.addParam('sysparam_role',$scope.selectedRole);
        immper.getXMLAnswer(function(response) {
            console.log("check",response);
           
            try {
                var userData = JSON.parse(response);
                $rootScope.selectedUser = userData;
                if (callback) callback();
            } catch (e) {
                console.error("Error parsing user data:", e);
            }
           
        });
    };
 
    var c = this;
    c.redirectToPage = function() {
        $scope.fetchUserDetails(function() {
           
            // Use $timeout
            $timeout(function() {
                window.location.href = '';
            }, 100);
        });
    };
};
 
 
script include
---------------------
var GetUserDetailsByPersona = Class.create();
GetUserDetailsByPersona.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getUser:function(){
    var persona = this.getParameter('sysparam_persona');
    var user = new GlideRecord('sys_user');
    if(persona == "New to Rallaint "){
        user.addQuery('active',true);
    }else if (persona == " New to OpCo")
    {
        user.addQuery('active',true);
    }
   
    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({});
}
   

});
0 REPLIES 0