Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

URL From Arguments - With Javascript

Community Alums
Not applicable

Morning All,

So I've created a script include to look up a users end user portal from their company (custom field):

function getUserPortal() {
    var company = gs.getUser().getCompanyID();
    var portalSuffix = new GlideRecord('core_company');
    portalSuffix.get(company);
    if (company) {
		var portal = portalSuffix.u_end_user_portal.url_suffix;
		portal = (portalSuffix.u_end_user_portal.url_suffix) ? '/' + portal + '?sysparm_stack=no' : '/esp?sysparm_stack=no';
		return portal;
    } else {
        return '/esp?sysparm_stack=no';
    }
}

I am then calling this in a URL from Arguments as:

javascript:getUserPortal();

However all that ever loads is a new blank tab, I've tried with client callable enabled and disabled. I've reviewed the other app modules using javascript but just can't seem to get this to work. I verified in a background script the correct URL is being returned.

Any suggestions appreciated, Thank you.

1 ACCEPTED SOLUTION

Hi,

 

You can try using processor to redirect url based on scripted logic.

Thanks.

View solution in original post

11 REPLIES 11

Community Alums
Not applicable

Hi Asha,

The script itself is within the Global scope.

I added the logging as gs.log and found the following:

If I call within gs.print from a background script it evaluates correctly and updates the log

If I run the menu link as javascript:getUserPortal(); Nothing happens, the log doesn't update;

If I run the menu link as:

/core_company_list.do?sysparm_offset=&sysparm_list_mode=grid&sysparm_query=u_end_user_portalLIKEjavascript:getUserPortal();

It evaluates and updates the query but does not update the log.

Community Alums
Not applicable

I simplified my code just to make it cleaner but still no dice when using the menu just to call javascript:getUserPortal();

I tried calling it like the debug modules do as well, and still nothing javascript:window.top.getUserPortal(); and javascript:window.open(getUserPortal());

 

function getUserPortal() {

    var company = gs.getUser().getCompanyRecord();
    var endUserPortal = company.u_end_user_portal;
    var portalSuffix = endUserPortal.url_suffix;

    if (company) {
        var portal = portalSuffix;
        portal = (portalSuffix) ? '/' + portal + '?sysparm_stack=no' : '/esp?sysparm_stack=no';
        return portal;
    } else {
        return '/esp?sysparm_stack=no';
    }
}