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

Monika2
Giga Guru

Hi Simon,

If your script include is in scope please check if the script include is available for all scope.

 

Regards,

Monika

Community Alums
Not applicable

Morning Monika,

The script is in the Global scope.

Ash10Patil
Kilo Guru

Hi,

 

1) Is script include in global scope?

2) Can you put logs in script to see if url is getting returned from script include?

 

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

gs.info("Portal URL [if statement]::"+portal);

return portal; }

else {

gs.info("Portal URL [else statement]::"+portal);

return '/esp?sysparm_stack=no';

}

}

 

Thanks.

Community Alums
Not applicable

Morning Asha,

The script is in Global scope.

 

I added logging to gs.log.

When I call from a background script the log updates.

When I click the menu option I get no logging and nothing happens.

However I updated the URL with arguments to be:

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

 

and it evaluated, however there was nothing in the log.