window.open() not working

shalini44
Tera Expert

Hello,

I am trying to open a newly created knowledge article in a new window. I am using a UI Action. The following code does not work:

var sysid = kbArticle.sys_id;

var url = 'kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);

    url += '&sysparm_stack=/kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);

    url += '&sysparm_view=default_view';

    window.open(url);//,'','width=800,height=700');

The error logs gives me the following:

org.mozilla.javascript.EcmaError: "window" is not defined.

Caused by error in <refname> at line 28

25: var url = 'kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);

26: url += '&sysparm_stack=/kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);

27: url += '&sysparm_view=default_view';

==> 28: window.open(url);//,'','width=800,height=700');

29:

But if I have the following line, it opens the knowledge article in the same window.

action.setRedirectURL(kbArticle);

Can anybody point out why the article does not open in a new window? Any help would be greatly appreciated.

Best Regards,

Shalini

3 REPLIES 3

victor_tufino
Giga Contributor

Hi Shalini,



what if   you use the following:



var sysid = kbArticle.sys_id;


var url = 'kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);


  url += '&sysparm_stack=/kb_knowledge.do?sys_id=' + encodeURIComponent(sysid);


  url += '&sysparm_view=default_view';


  top.window.open(url);//,'','width=800,height=700');


Thank you Victor!


This was a very old question (more than 2 year back) and I think we had figured out the solution.


Thanks for your reply.\


//Shalini


Matt Dumont1
Mega Expert

Shalini,



          This article may be of some use to you.   In order for a UI action to run on the client side, you need to make sure the "Client" checkbox is checked.   Both "top.window" and "window" will be defined in that case.   Hope this helps!