Open Incident from UI Action with Parameters

nannette
Mega Contributor

I would like to create an Incident from a UI Action and populate two fields on the incident.

I have this code but it doesn't respond.   I have also used the GlideDilogWindow and but I can't seem to pass the values to the Incident form

function redirectToIncident()

{

     

      var uniqueid = current.u_caller_unique_id;

      var sysId = current.sys_id;

        var url = new GlideURL("incident.do");

              url.addParam("sysparm_caller_id", sysId);

              url.addParam("sysparm_u_caller_unique_id", uniqueid);

          var w = getTopWindow();

              w.popupOpenFocus(url.getURL(), '_blank', false, false);

     

     

      }

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

There are several ways to do this, what you're doing is a separate popup rather than a redirect.   If you want to redirect you can look at the 'Create Problem' UI action for an example in the system.   If you want to adjust your code so that you get a popup you could change it to something like this that uses 'sysparm_query' to populate field values as shown here...



Populating Default Values with a URL or Module - ServiceNow Guru



function redirectToIncident(){


    //Client-side get record sys_id


    var sysID = g_form.getUniqueValue();



    //Base URL for creating a new incident record and populating fields via 'sysparm_query' parameter


    var url = '/incident.do?sys_id=-1&sysparm_query=';



    //Query parameter for populating fields on the incident form.   Adjust this as needed.


    var urlParams = 'caller_id=' + sysID



    //Pop up window


    var w = getTopWindow();


    w.popupOpenFocus(url + urlParams, '_blank', false, false);


}


View solution in original post

10 REPLIES 10

Mark Stanger
Giga Sage

There are several ways to do this, what you're doing is a separate popup rather than a redirect.   If you want to redirect you can look at the 'Create Problem' UI action for an example in the system.   If you want to adjust your code so that you get a popup you could change it to something like this that uses 'sysparm_query' to populate field values as shown here...



Populating Default Values with a URL or Module - ServiceNow Guru



function redirectToIncident(){


    //Client-side get record sys_id


    var sysID = g_form.getUniqueValue();



    //Base URL for creating a new incident record and populating fields via 'sysparm_query' parameter


    var url = '/incident.do?sys_id=-1&sysparm_query=';



    //Query parameter for populating fields on the incident form.   Adjust this as needed.


    var urlParams = 'caller_id=' + sysID



    //Pop up window


    var w = getTopWindow();


    w.popupOpenFocus(url + urlParams, '_blank', false, false);


}


Mark,



It acts like its trying to open a old incident.   I removed sys_id = -1 and it still says record not found.



I also have two parameters I'm passing but if i get the caller_id set I can then set the other value on the page



function redirectToIncident()



{


     


      //var uniqueid = g_form.getValue(u_caller_unique_id);


      var sysId = g_form.getUniqueValue();


        var url = ("incident.do?sysparm_query=");


      var urlParam1 = 'caller_id=' + sysId


      //var urlParam2 = 'u_caller_unique_id=' + uniqueid;


      var w = getTopWindow();


      w.popupOpenFocus(url + urlParam1, '_blank', false, false);


      //window.open('incident.do?', '_blank')


     


            // getTopWindow().popupOpenFocus("incident.do?", "_blank", null, null, "");


     


      }


You need to keep 'sys_id=-1' there, that's what indicates that it should create a new incident rather than open some random old one.   Where are you initiating this UI action from?   I assumed the user form.   Is 'u_caller_unique_id' the name of a field on the incident form?   If so, what is the corresponding name of the field on the user form?


yes i add it back and it did open the incident and set the caller_id.



Now i need to set another value on the page '



Thanks