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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Lkr 

 

What error you are getting? Is it creating Change or not if yes in same window?

*************************************************************************************************************
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]

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

Hi @Dr Atul G- LNG 

I have tried several things. When I get the functionality to work where the change is opened in a new window, the fields are not copied into the change. Otherwise, I have tried other codes where the button does not create any action. 
So I both need to include script that opens up a new window, create a new change and copy information from the ritm into that change. So as I understand both server-side and client-side script hopefully in one ui action.

@Lkr 

 

Did you check the properties to copy the fields also give a try at @Samaksh Wani  Solution as well. 

*************************************************************************************************************
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]

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

Samaksh Wani
Giga Sage
Giga Sage

Hello @Lkr 

 

use this instead of action.setRedirectURL

 

window.open('your URL','_blank');

 

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

 

Regards,

Samaksh