I need to close the record and redirect to the CWS Home page

DeepikaR1661877
Tera Contributor

Hello every, 

I am creating one client script to bolck the SIR form in CWS workspace, i have create one client script it's working fine but the record number is on next tab, i want to close the record and redirect to the home page , any one help on this, just want to add the one condition like the closed the record and redirect to the home page,

 

function onLoad() {
    var currentUrl = top.location.href; 
  if (currentUrl.includes("now/sir")) {
    //alert(" This is a Security Incident Record in Workspace.");
    
}
else{
 
alert("Access to Security Incident records is restricted outside the SIR Workspace. You are being redirected to the home page.");
  var baseIndex = currentUrl.indexOf("/record");
     var baseUrl = currentUrl.substring(0, baseIndex);
     top.location.href = baseUrl; // This takes you to the workspace landing page
 
}
 
Thanks,
Deepika ravindran
14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@DeepikaR1661877 

share some screenshots.

Your requirement is not clear.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

DeepikaR1661877
Tera Contributor

DeepikaR1661877_0-1753796023202.png

Hi @Ankur Bawiskar , 

Please find the above screen shot, actually the issue is I need to block the SIR record in other workspace, so i have write the client script to block the from, now it's blocking and redirect to the home but you can see the that record tab is not closed after the home page, now i want the solution is need to close the record tab and redirect to the home page,

 

Thanks,

Deepika

@DeepikaR1661877 

image is not visible.

Security Incident should be opened only in particular workspace and not allowed in native and in any other workspace?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@DeepikaR1661877 

this worked for me for workspaces.

I used g_aw.closeRecord(); to close the tab in workspace.

When I opened INC in CSM/FSM workspace, it gave me alert, closed the record and redirected to the CSM/FSM workspace base URL

function onLoad() {
    var currentUrl = top.location.href;
    if (currentUrl.includes("/sow")) {
        //alert(" This is a Incident Record in SOW.");
    } else {
        alert("Access to Incident records is restricted outside the SOW Workspace. You are being redirected to the home page.");
        var baseIndex = currentUrl.indexOf("/record");
        var baseUrl = currentUrl.substring(0, baseIndex);
        top.location.href = baseUrl; // This takes you to the workspace landing page
        g_aw.closeRecord();
    }
}

Output:

restrict incident from other workspace and close the record.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader