redirect to new window through UI Action

DB1
Tera Contributor

Hello All,

 

I have the below script UI Action which converts RITM to INC.

I need help in opening the newly created INC in a new tab. How do I do it from client side as I now understand it cannot be done through server side

 

function openinc() {

    var usrResponse = confirm('Are you sure you would like to proceed?');

    if (usrResponse)
        gsftSubmit(null, g_form.getFormElement(), 'transfer_incident');

}

if (typeof window == 'undefined')
    runBusRuleCode();

//Server-side function
function runBusRuleCode() {

    var ritmTable = current.getTableName();
    var ritmSysID = current.getUniqueValue();
    var ritmNum = current.getValue('number');
    var comments = 'Incident created from ' + ritmNum;

    var inc = new GlideRecord("incident");

    inc.caller_id = current.request.requested_for;
    //inc.assignment_group = assignmentGroup;
    inc.short_description = current.short_description;
    inc.cmdb_ci = current.cmdb_ci;
    inc.assignment_group = current.assignment_group;
    inc.business_service = current.business_service;
    inc.impact = current.impact;
    inc.urgency = current.urgency;
    inc.description = current.variables.description;
    inc.contact_type = 'self-service';
    inc.u_initiated_by = current.request.opened_by;
    inc.comments = comments;
    inc.parent = ritmSysID;
    var incSysID = inc.insert();
    var incTable = inc.getTableName();
    var incNum = inc.getValue('number');
    GlideSysAttachment.copy(ritmTable, ritmSysID, incTable, incSysID);
    current.comments = 'RITM converted to  ' + incNum + '. Please use this reference from now on.';
    current.state = 4;


    //

    var taskRec = new GlideRecord('sc_task');
    taskRec.addQuery('request_item', current.sys_id);
    taskRec.addEncodedQuery('stateIN-5,1,2');
    taskRec.query();
    while (taskRec.next()) {
        taskRec.state = 4;
        taskRec.update();
    }

    //

    current.update();
    //gs.log("state " + current.state);
    gs.addInfoMessage(gs.getMessage("Incident {0} created", incNum));
    //action.setRedirectURL(inc);
    //action.setReturnURL(current);
    //gs.setRedirect("incident.do?sys_id=" + incSysID);

    var url = "incident.do?sys_id=" + incSysID;
    g_navigation.open(url);

}

 

@Ankur Bawiskar @Ravi Gaurav @Runjay Patel @Sandeep Rajput @Chuck Tomasi 

1 ACCEPTED SOLUTION

@DB1 

I hope your UI action is client side

Script include is not client callable

seems you didn't copy it exactly what I gave in script include.

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

View solution in original post

9 REPLIES 9

Viraj Hudlikar
Tera Sage

Hello @DB1 

Check this thread which will be helpful to you.
Convert an RITM to an Incident - ServiceNow Community

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

Thanks & Regards
Viraj Hudlikar.

I tried but the redirect is not working

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

that's correct you cannot open in new tab using server side

The only way is this

1) make the UI action client side

2) use GlideAjax to create record, copy etc and update the current record

3) that script include function will return sysId and then you can open in new tab using g_navigation

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

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

something like this

UI Action:

AnkurBawiskar_0-1738163443813.png

 

function convertRecord() {
    var usrResponse = confirm('Are you sure you would like to proceed?');
    if (usrResponse) {
        var ga = new GlideAjax('ConvertRecord');
        ga.addParam('sysparm_name', 'convertMyRecord');
        ga.addParam('sysparm_sysId', g_form.getUniqueValue());
        ga.getXMLAnswer(function(answer) {
            var url = "incident.do?sys_id=" + answer;
            g_navigation.open(url, '_blank');
        });
    }
}

Script Include: Client callable

var ConvertRecord = Class.create();
ConvertRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    convertMyRecord: function() {

        var ritmSysID = this.getParameter('sysparm_sysId');
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(ritmSysID)) {
            var comments = 'Incident created from ' + ritm.number;

            var inc = new GlideRecord("incident");
            inc.caller_id = ritm.request.requested_for;
            inc.short_description = ritm.short_description;
            inc.cmdb_ci = ritm.cmdb_ci;
            inc.assignment_group = ritm.assignment_group;
            inc.business_service = ritm.business_service;
            inc.impact = ritm.impact;
            inc.urgency = ritm.urgency;
            inc.description = ritm.variables.description;
            inc.contact_type = 'self-service';
            inc.u_initiated_by = ritm.request.opened_by;
            inc.comments = comments;
            inc.parent = ritmSysID;
            var incSysID = inc.insert();
            GlideSysAttachment.copy(ritm.getTableName(), ritmSysID, inc.getTableName(), incSysID);
            ritm.comments = 'RITM converted to ' + inc.number + '. Please use this reference from now on.';
            ritm.state = 4;
            ritm.update();

            var taskRec = new GlideRecord('sc_task');
            taskRec.addQuery('request_item', ritmSysID);
            taskRec.addEncodedQuery('stateIN-5,1,2');
            taskRec.query();
            while (taskRec.next()) {
                taskRec.state = 4;
                taskRec.update();
            }
            return incSysID;
        }
        return '';
    },

    type: 'ConvertRecord'
});

I hope you should enhance it based on your requirement and debug further with your developer skills.

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