Create Request from an Incident passing variables

juliana3
Tera Contributor

I need to convert INC to RITM and RITM to INC, but what I want is to lead the analyst to the catalog page so he can choose the new category and then have all the form filled with data from incident.

I tried doing something like this:

var url = "catalog_home.do?sysparm_view=catalog_default&sysparam_caller_id=";

Service catalog client:

var requester = getParmVal('sysparm_caller_id');

if (requester){

g_form.setValue('caller_id',requester);

But it didn't work, it seems like the parameter is lost after you navigate through service catalog.

5 REPLIES 5

I've done a similar thing using an link in an email message.   It should work with a redirect.


The link was from an HR Onboarding Form and was used to open a Manager's Onboarding Form and transfer much of the information to the new RITM.



The URL looks like this:


https://<YOUR INSTANCE>.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=<SYSID_OF_CAT_ITEM>&sysparm_hrform=<SYSID_OF_SOURCE_RITM>




I also have two catalog client scripts.   One to parse the URL variable for the source RITM and a second to open the source RITM and scan through it's variables.   Here's a sample of the scripts with the logic simpified:


Note that the source RITM record is stored in the variable named "hr_onboarding_form".   You should use whatever name makes sense to your application.


EDIT:   The variable "hR_onboarding_form" is a reference variable to the sc_req_item table with a filter for the HR Onboarding Form as the item.




Script 1: ( onload ) ------------------------------- BEGINING OF SCRIPT ---------------------


function onLoad() {


  //Populate the variables with the parameters passed in the URL


  //Use the 'getParmVal' function below to get the parameter values from the URL


  var id = getParmVal('sysparm_hrform');


  if(id){


          g_form.setValue('hr_onboarding_form',id);


  }


}



function getParmVal(name) {


  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");


  var regexS = "[\\?&]"+name+"=([^&#]*)";


  var regex = new RegExp(regexS);


  var results = regex.exec( window.location.href );


  if(results == null){


          return "";


  }


  else{


          return unescape(results[1]);


  }


}


Script 1: ( onload ) ------------------------------- END OF SCRIPT ---------------------




Script 2: ( onChange, variable hr_onboarding_form ) ------------------------------- BEGINNING OF SCRIPT, SORRY ABOUT THE INDENTATION.   IT MESSES UP IN THIS EDITOR ---------------------


function onChange(control, oldValue, newValue, isLoading) {


if ( newValue != "" )


{


var hr_form = new GlideRecord('sc_req_item');


hr_form.addQuery('sys_id', newValue);


hr_form.query();


while (hr_form.next())


{


var mtom = new GlideRecord('sc_item_option_mtom');


mtom.addQuery('request_item', hr_form.sys_id);


mtom.query();


while (mtom.next())


{


var option = new GlideRecord('sc_item_option');


option.addQuery('sys_id', mtom.sc_item_option);


option.query();


while (option.next())


{


var question = new GlideRecord('item_option_new');


question.addQuery('sys_id', option.item_option_new);


question.query();


while (question.next())


{


if ( question.name == "first_name" )


{


g_form.setValue('first_name', option.value);


} else if (   question.name == "last_name" )


{


g_form.setValue('last_name', option.value);


} else if ( question.name == 'employee_id')


{


g_form.setValue('employee_id', option.value);


} else if ( question.name == 'preferred_name')


{


g_form.setValue('preferred_name', option.value);


}



}


}



}


}


}


else


{


g_form.setValue('first_name', "");


}




}


Script 2: ( onChange, variable hr_onboarding_form ) ------------------------------- END SCRIPT ---------------------