Glide Ajax is returning null value in UI script

Deepak89
Tera Expert

Hello Guys,

i am calling script include from UI script , but i am getting null response ( alert line 10)  , if you may say that issue in Script include but i have tested same si in on load script and it gave my response but UI script its giving null

  

UI Script :

 

addLoadEvent(function() {
    var url = document.URL;


    var company = new GlideAjax('SOG_UserCompany');
    company.addParam('sysparm_name', 'getComp');
    company.addParam('sysparm_user', g_user.userName );
    company.getXMLWait();
    var x = (company.getAnswer());
    //alert(x);
   

    if (g_user.hasRoleExactly('snc_external', true) && !g_user.hasRoleFromList('snc_internal, admin', true) && document.URL.indexOf('.do') != -1) {


        var mfaUrl1 = '/multi_factor_auth_setup_page.do';
        var mfaUrl2 = '/validate_multifactor_auth_code.do';
        var mfaUr13 = 'assessment_take2.do';
        if (url.indexOf(mfaUrl1) > 0 || url.indexOf(mfaUrl2) > 0 || url.indexOf(mfaUr13) > 0) {
            //ignore expections
            return;
        }
        window.location = x;
    }


});
 
 
Script Include ;
 
var SOG_UserCompany = Class.create();
SOG_UserCompany.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getComp: function() {
        var user = this.getParameter("sysparm_user");
        var userRecord = new GlideRecord("sys_user");
        userRecord.get("sys_id", user);

        //  var userCompanyID = gs.getUser().getCompanyID();
        // Gemeente Amsterdam
        if (userRecord.company == "a3cc7a2c8754fc1065cfcbb5cebb3529") {
            return "/adw";
        }
        //ISEC
        else if (userRecord.company == "4116f7d1978aa590bc7abaffe153afa4") {
            return "/isec";
        }
        //Every body else
        else {
            return "/csm";
        }
    },

    type: 'SOG_UserCompany'
});
7 REPLIES 7

Sandeep Rajput
Tera Patron
Tera Patron

@Deepak89 Can you update the UI Script as follows.

 

addLoadEvent(function() {
    var url = document.URL;
    var company = new GlideAjax('SOG_UserCompany');
    company.addParam('sysparm_name', 'getComp');
    company.addParam('sysparm_user', g_user.userName );
    company.getXMLWait();
    var x = company.getAnswer();
    //alert(x);


    if (g_user.hasRoleExactly('snc_external', true) && !g_user.hasRoleFromList('snc_internal, admin', true) && document.URL.indexOf('.do') != -1) {


        var mfaUrl1 = '/multi_factor_auth_setup_page.do';
        var mfaUrl2 = '/validate_multifactor_auth_code.do';
        var mfaUr13 = 'assessment_take2.do';
        if (url.indexOf(mfaUrl1) > 0 || url.indexOf(mfaUrl2) > 0 || url.indexOf(mfaUr13) > 0) {
            //ignore expections
            return;
        }
        window.location = x;
    }


});

Hello Sandeep,

Giving null .

is it bcoz i have use   g_user.userName  but i can not able to find to find how can i get logged user details 

Deepak89_0-1708617785392.png

 

Also let me add i am impersonating as end user  which is portal page and then try opening backend URL (like incident.list ) , i am trying to redirect user to based on output from SI  , but its redirecting to null suffix at end but i want to set it based on output from SI where am sending suffix and then setting window.location = return sufix from SI

Deepak89_1-1708618408152.png

 

 

 

@Deepak89 You are fetching userName in UIScript and in script include the glide record is checking with sys_id. Update the script as follows.

 

addLoadEvent(function() {
    var url = document.URL;
    var company = new GlideAjax('SOG_UserCompany');
    company.addParam('sysparm_name', 'getComp');
    company.addParam('sysparm_user', g_user.userID );
    company.getXMLWait();
    var x = company.getAnswer();
    alert(x);


    if (g_user.hasRoleExactly('snc_external', true) && !g_user.hasRoleFromList('snc_internal, admin', true) && document.URL.indexOf('.do') != -1) {


        var mfaUrl1 = '/multi_factor_auth_setup_page.do';
        var mfaUrl2 = '/validate_multifactor_auth_code.do';
        var mfaUr13 = 'assessment_take2.do';
        if (url.indexOf(mfaUrl1) > 0 || url.indexOf(mfaUrl2) > 0 || url.indexOf(mfaUr13) > 0) {
            //ignore expections
            return;
        }
        window.location = x;
    }


});