Open new window in Agent Workspace

ayanc27
Kilo Expert

Hello everyone,

I want open a new window / tab by clicking on UI Action button in Agent Workspace to open an external url. From UI 16 it is working fine but in Agent Workspace it is not opening any new tab or window. I tried below but no luck:

 

1> window.open("https://www.google.com",'_blank');

2> g_navigation.openPopup("https://www.google.com");

 

 

Any help is appreciated. Thanks in advance

 

14 REPLIES 14

Thank you, this helped. To make it simpliar, the following also works:

top.window.open('http://www.coolsite.com', '_blank');

 Without need to assign it to a variable and triggering the focus()

ayanc27
Kilo Expert

HI Everyone, Please find the solution below:

 

The main trick is to open a browser from a custom defined function instead calling from onClick() function of agent workspace. Call the custom method/function from onClick(), then the page will get opened in new tab. See my code below.

 

function onClick(g_form) {
// Current context (anonymous method executed by Agent Workspace)
openUrl("<Define your URL>");
}

function openUrl(url) {
// Current context the window of Agent Workspace
this.open(url,'_blank');
}

 

Hope this will help. Thanks!

Please mark as helpful and Mark as Answer

i can open my UI Page in new window. but OK, CANCEL buttons not working , so can you suggest how to fix issue?

UI Action:

function onClick(g_form) {
openUrl('/task_comments_dialog.do?sysparm_id=' + g_form.getSysId() + '&sysparm_isWorkspace=true');    
}
function openUrl(url) {
// Current context the window of Agent Workspace
this.open(url);
}

 

UI Page HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<!-- Get values from dialog preferences passed in -->
<g:evaluate var="jvar_short_text"
expression="RP.getWindowProperties().get('short_text')" />
<g:evaluate var="jvar_comments_text"
expression="RP.getWindowProperties().get('comments_text')" />



<table width="100%" height="100%">

<tr id="description_row" valign="top">
<td colspan="5">
<!-- Short description value used as a label -->
${jvar_short_text}
</td>
</tr>

<tr>
<td>

<g:ui_multiline_input_field name="dial_comments" label="Additional comments" value="${jvar_comments_text}" mandatory="true" />

<label style="display: block;">Contact Type</label>
<g:ui_choicelist name='HoldReason' label="Contact Type" table='incident' field='contact_type'/>

<label style="display: block;">Business Service</label>
<g:ui_reference name="input_business_service" table="cmdb_ci_service" query="nameNOT LIKEBlackberry" label="Business service"/>


</td>
</tr>

<tr>
<td colspan="2">
</td>
</tr>

<tr id="dialog_buttons">
<td colspan="5" align="right">
<g:dialog_buttons_ok_cancel ok="return validateComments()" ok_type="button" cancel_type="button" />
</td>
</tr>

</table>

</j:jelly>

client script:

function validateComments() {
var businessservice=gel("input_business_service").value;
var comments = gel("dial_comments").value;
var contacttype=gel("HoldReason").value;

comments = trim(comments);
if ((comments == "" )||(businessservice=="")||(contacttype==""))

{
alert("Please Fill fields to submit the dialog.");
return false;
}

GlideDialogWindow.get().destroy();
g_form.setValue("comments", comments);
g_form.setValue('business_service',businessservice);
g_form.setValue('contact_type',contacttype);

}

 

find_real_file.png

were you able to make it work?

 

mazachary
ServiceNow Employee
ServiceNow Employee

@ayanc27  - This worked perfectly!  Thanks for your help.