- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 08:35 AM
I have written below code in ui action client script , it is working fine if but it is opening a link in new window outside of agent workspace but I want to open it in the new tab with n agent workspace only. Could someone help me how should I achieve this.
function onClick(g_form) {
var url = 'sp?id=sc_cat_item&sys_id=14287122db109050665dd855ca961914&parent=' + g_form.getUniqueValue();
open(url);
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2021 11:48 AM
My bad I thought you want to open new browser tab.
To open inside the workspace tab, have you checked g_service_catalog.openCatalogItem()
eg: you can refer ootb UI Action, "Create Request"
Reference:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2021 01:50 AM
Thanks so much Harsh. I marked the answer helpful and I am also able to figure out about that error but not able to resolve that.
In the catalog item there is client script written to check attachments in which sp_form is there due to which it is causing error and always throwing exception.
Can you please help me how should I fix this. I have highlighted the line which is causing the issue in agent workspace.
function onSubmit() {
var errorMessage = "Before you can submit this request, you must attach a screen shot to assist with troubleshooting.";
try {
//if document and gel available, in old iframe view. Check attachments using older methods
//Otherwise try using new method for OOB portal widgets
if (document && gel) {
var ajax = new GlideAjax('checkAttachments');
ajax.addParam('sysparm_name', 'checkAttach');
ajax.addParam('sysparm_user', g_user.userName);
if (gel('sysparm_item_guid') !== null) {
ajax.addParam('sysparm_sys_id', gel('sysparm_item_guid').value); //itens
} else {
ajax.addParam('sysparm_sys_id', gel('sysparm_cart_edit').value); //order guide
}
ajax.getXMLWait();
if (ajax.getAnswer() == 'false') {
top.sweetAlert(errorMessage, '', 'error');
return false;
} else {
return true;
}
} else {
var catItemId = g_form.getUniqueValue();
if (!sp_form.hasRequiredAttachments(catItemId)) {
g_form.addErrorMessage(errorMessage);
return false;
}
return true;
}
} catch (e) {
g_form.addErrorMessage("Error - unable to check attachments - contact support for troubleshooting by navigating <a href='https://instance.service-now.com/sp?id=sc_cat_item&sys_id=c19b74e5dbc497008e14ff431d961980'>here</a> and completing the form.<br><br>Error detected: " + e);
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2021 05:32 AM
You can put the alert to check sp_form.hasRequiredAttachments(catItemId) value,
Anyway, alternate solution. try with below blog solution, see if it is working or not.
https://community.servicenow.com/community?id=community_blog&sys_id=00edd9751bb090d0ada243f6fe4bcba8

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2021 08:28 PM
Any update on this thread?
Do you need any further help ?
If my answer helped you, kindly mark it as correct and close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2021 08:34 PM
Thanks Harsh for the help. I have marked the answer correct to close the thread.