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

Hi Simon,

 

Are you saying it is working now as expected?

If you don't see any log, it means it is breaking before those statements or function is not getting called at all.

May be put log at the 1 line in that function just to check if function is getting called or not.

 

Thanks.

Community Alums
Not applicable

Asha,

No unfortunately it is not. When I run it as intended just as "javascript:getUserPortal();"

It does not load anything. Yet works perfectly when I evaluate as a background script.

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();

 

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';
    }
}

Hi,

 

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

Thanks.

Community Alums
Not applicable

You know one of those moments you feel really stupid.. this is one of those.

 

Thank you, I've used processors a bunch so I don't know why I didn't think of that.