Catalog Client Script - ReferenceError: g_navigation is not defined

Oliver Anderson
Kilo Sage

I have a Catalog Item with one Select Box variable. Depending on the choice the user selects, I want the page to redirect to a different Catalog Item URL. I have created a Catalog Client Script on the Catalog Item called "Redirect URL." It has the following onChange script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	//Type appropriate comment here, and begin script below
	var value = g_form.getValue('mt_issue_access');
	var accessUrl = 'sp?id=sc_cat_item&table=sc_cat_item&sys_id=42d84a101b1df5102d36751bdd4bcbe7';
	
	if (value == 'issue') {
		return;
	} else if (value == 'access') {
		g_navigation.open(accessUrl);
	}
}

The IF statement should open the URL specified when the "Request software access" choice is selected. However, when selecting that choice, I am getting the following Java exception: Error while running Client Script "Redirect URL": ReferenceError: g_navigation is not defined

javaexception.png

According to the documentation, it seems like g_navigation is a client-side class, so I'm not sure why it is showing as undefined. Here is the Catalog Client Script if needed:

clientscript.png

1 ACCEPTED SOLUTION

Hemanth M1
Giga Sage
Giga Sage

Hi @Oliver Anderson ,

try  top.window.location(accessUrl)

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

5 REPLIES 5

Hemanth M1
Giga Sage
Giga Sage

Hi @Oliver Anderson ,

try  top.window.location(accessUrl)

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Tried this and got an error stating top.window.location() is not a function

 

So I did top.window.location = accessUrl and that did work, thank you!

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}

	//Type appropriate comment here, and begin script below
	var value = g_form.getValue('mt_issue_access');
	var accessUrl = 'sp?id=sc_cat_item&table=sc_cat_item&sys_id=42d84a101b1df5102d36751bdd4bcbe7';
	
	if (value == 'issue') {
		return;
	} else if (value == 'access') {
		top.window.location = accessUrl;
	}
}

However, now I'm realizing that the browser is going to warn that work may be lost, since they have technically filled out the request. Any ideas on how to bypass this warning and immediately redirect to the URL?

OliverAnderson_0-1694456383159.png

 

@Hemanth M1 I used Google and found this lol:

 

top.window.onbeforeunload = null;

 Inserting this code before the top.window.location line prevented the popup from appearing. Everything is working perfectly now, thank you!

and thank you for this too 🙂