UI Action create new change and open in new tab

Lkr
Tera Contributor

Hello,

 

I would like to receive some help. I have tried to solve this functionality request, but haven't succeeded, so therefore I am reaching out to this amazing community. 

 

I would like to change our current UI action, which creates a change request from a RITM and transfers some of the RITM fields into the Change fields. The change should now include that it also opens the new change in a new window. Currently the ritm window is being refreshed, as per SN default. However, my colleagues would like to keep having the RITM open while opening the change request. 

So how can I add that functionality of opening the change in a new window tab? 

 

I have tried to include it in the script as per other community post solutions and check the client script, but haven't suceeded yet. Errors keep popping up when trying to include both server and client side script in the same ui action. 

 

Let me know if further info is needed. 

 

Thanks! 

1 ACCEPTED SOLUTION

JohnnySnow
Kilo Sage

Hi @Lkr, In UI actions you can pass value from client to server & not the other way around. To open a URL in new window you can use below code(you might have to tweak as per your requirement though):

 

1. Create a Client callable script include

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

    getNewWindow: function() {
		
	var parentID = this.getParameter('sysparm_url');

//below code is from the OOTB Create Change UI action      
  var url = new GlideURL("change_request.do");
       url.set("sys_id", "-1");
        url.set("sysparm_query", "^parent=" + parentID);

 		var finalStr = url.toString();
		return finalStr;
    },
    type: 'ChangePopupTest'
});

 

2. In the original Create Change UI action, select 'Client' checkbox, add call below function in the onClick field & add below code in the script.

JohnnySnow_0-1703029535724.png

 

function fetchURL() {
    var ga = new GlideAjax('ChangePopupTest');
    ga.addParam('sysparm_name', 'getNewWindow');
    ga.addParam('sysparm_url', g_form.getUniqueValue());
    ga.getXML(showPopup);

    function showPopup(response) {
        var newURL = response.responseXML.documentElement.getAttribute("answer");
        g_navigation.openPopup(newURL);

    }

}

 

Please mark helpful and correct if it resolved your issue.

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

Lkr
Tera Contributor

Hi @Samaksh Wani 
Thank you, have tried without luck. Could it be because i use wrong URL in ('you URL',"_blank'); 
What could an example be if the url should be the newly created change_request.do? 

Hello @Lkr 

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

I doubt it should be full Url like : instance.servcie-now.com/tablename.do

Like we we use in integration.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Reddy
Kilo Sage

@Lkr"I am in a similar situation as you. Have you managed to achieve your goal?"

JohnnySnow
Kilo Sage

Hi @Lkr, In UI actions you can pass value from client to server & not the other way around. To open a URL in new window you can use below code(you might have to tweak as per your requirement though):

 

1. Create a Client callable script include

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

    getNewWindow: function() {
		
	var parentID = this.getParameter('sysparm_url');

//below code is from the OOTB Create Change UI action      
  var url = new GlideURL("change_request.do");
       url.set("sys_id", "-1");
        url.set("sysparm_query", "^parent=" + parentID);

 		var finalStr = url.toString();
		return finalStr;
    },
    type: 'ChangePopupTest'
});

 

2. In the original Create Change UI action, select 'Client' checkbox, add call below function in the onClick field & add below code in the script.

JohnnySnow_0-1703029535724.png

 

function fetchURL() {
    var ga = new GlideAjax('ChangePopupTest');
    ga.addParam('sysparm_name', 'getNewWindow');
    ga.addParam('sysparm_url', g_form.getUniqueValue());
    ga.getXML(showPopup);

    function showPopup(response) {
        var newURL = response.responseXML.documentElement.getAttribute("answer");
        g_navigation.openPopup(newURL);

    }

}

 

Please mark helpful and correct if it resolved your issue.

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.