Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Call record producer from UI Action

cre1014
Kilo Expert

Is it possible to call a record producer from an UI Action and place values from the current form into variables on that record producer?

I am attempting to create a new catalog item request from a CMDB table. Whenever I click on the UI Action it should populate the record producer and submit it without leaving the current page that I'm on. I know you can get the session variables and send it a record producer via client script, but I'm looking to stay on the original page without being redirected.

Is this possible? Any help is appreciated!

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Caitlyn,



The below thread should answer your question.


Check out the "Parameter


Pradeep,



I saw this thread, but I don't think it's addressing my question. They are still redirecting to the record producer after clicking on the UI Action to submit it; I need to not redirect but still submit the record producer. Is this part possible?


mikeblack
Tera Contributor

Hi, You can do this with the help of the session variables. The petty similar things i have done in one of my implementation.



UI Action Script:



var gr=new GlideRecord('sc_cat_item_category');


  if(gr.get('sc_cat_item.name','Record Producer name')){


  var item= gr.sc_cat_item;


  }




var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' +   item +'';



gs.getSession().putClientData('value1', current.name);


gs.getSession().putClientData('value2', current.ip_address);


gs.getSession().putClientData('value3', current.company);


gs.getSession().putClientData('value4', current.change_control);


gs.getSession().putClientData('value5', current.support_group);


gs.getSession().putClientData('value6', current.short_description);


gs.getSession().putClientData('value7', current.u_retirement_date);


gs.getSession().putClientData('value8', current.operational_status);




action.setRedirectURL(url);




Record Producer Client Script:



function onLoad() {


  //Type appropriate comment here, and begin script below


  g_form.setValue('name',g_user.getClientData('value1'));


  //g_form.setValue('ip_address',g_user.getClientData('value2'));


  g_form.setValue('company',g_user.getClientData('value3'));


  g_form.setValue('chg_app_group',g_user.getClientData('value4'));


  g_form.setValue('support_group',g_user.getClientData('value5'));


  g_form.setValue('description',g_user.getClientData('value6'));


  g_form.setValue('retired_date',g_user.getClientData('value7'));


  g_form.setValue('ops_status',g_user.getClientData('value8'));


}


mikeblack
Tera Contributor

Sorry, i missed the last part.



you have to use saveProducer(' '); in the client script and make sure all the mandatory fields are filled .


Then it will automatically submit the record producer.



function onLoad() {


  //Type appropriate comment here, and begin script below


  g_form.setValue('name',g_user.getClientData('value1'));


  //g_form.setValue('ip_address',g_user.getClientData('value2'));


  g_form.setValue('company',g_user.getClientData('value3'));


  g_form.setValue('chg_app_group',g_user.getClientData('value4'));


  g_form.setValue('support_group',g_user.getClientData('value5'));


  g_form.setValue('description',g_user.getClientData('value6'));


  g_form.setValue('retired_date',g_user.getClientData('value7'));


  g_form.setValue('ops_status',g_user.getClientData('value8'));



saveProducer(' ');


}