UI Action to Load New Record and populate information, but not submit

Andrew Linenber
Kilo Expert

Hello:

We are working on a scoped app and want to create a UI action to load a form on another table in the app with some information, but not actually submit the record.

So, from Record A (already submitted) on Table A, click "Generate", which will then lead to the form for a record on Table B, but not yet submitted.

I can use the following to load the form, but not have any information populated:

createRecord();

function createRecord() {
	
	var url = 'TableB.do';
	action.setRedirectURL(url);
	action.setReturnURL(current);
		
}

and I can use the following to automatically submit the form with the requested information

createRecord();

function createRecord() {
	var accomm = new GlideRecord ('TableB');
	accomm.tableB_field2 = current.getValue('tableA_field1');
	accomm.tableB_field2 = current.getValue('tableA_field2');
	action.setRedirectURL(accomm);
	action.setReturnURL(current);

but I can't rectify the two.

The functionality we want to replicate is **similar to*** the "New" Button on the Child incident related list on incident; when you click it (at least in our instance) it loads a blank incident form with some of the fields preloaded, but has not yet submitted the record. I need the UI action I am creating to do that, but lead from Form A to Form B with some fields on form B prepopulated  When I attempted to track down how that button works, I couldn't find it.

find_real_file.png

 

Any help is greatly appeciated.

 

1 ACCEPTED SOLUTION

nthumma
Giga Guru

You can pass the field values using the URL using sysparm_query like below

https://instance.service-now.com/incident.do?sys_id=-1&sysparm_query=state=1

 

Please read below docs to understand more

https://docs.servicenow.com/bundle/jakarta-platform-user-interface/page/use/navigation/concept/c_NavigatingByURL.html

 

 

 

 

View solution in original post

8 REPLIES 8

HI,


Can you please mark answer as correct and close this thread.


Thanks,

Ashutosh Munot

nthumma
Giga Guru

You can pass the field values using the URL using sysparm_query like below

https://instance.service-now.com/incident.do?sys_id=-1&sysparm_query=state=1

 

Please read below docs to understand more

https://docs.servicenow.com/bundle/jakarta-platform-user-interface/page/use/navigation/concept/c_NavigatingByURL.html

 

 

 

 

Just to enhance the answer.

If there are more parameters to be added, you can use client side GlideURL API to construct the URL and open the record using the same method.

It would just be refactoring of the above code using ServiceNow Client Side API.

 

 

var gu = new GlideURL('incident.do');
gu.addParam('sys_id', '-1');
gu.addParam('short_description', 'Dummy short description');
window.open(gu.getURL()); //Need to uncheck isolate script
//g_navigation.open() method can also be used, but it only works on gsft_main frame, not on the top frame.
g_navigation.open(gu.getURL(), '_blank'); //NO need uncheck isolate script <secure>

 

 

 

Best Regards,

Swarnadeep Nandy 

Brian Lancaster
Tera Sage

Can you provide the final code you used?  I have similar requirement and I can get the fields to show in the URL that I want to copy but I'm note sure how to then get them to set the actual field.

I have my own post for this: https://community.servicenow.com/community?id=community_question&sys_id=a9e147eadbdfe3002e8c2183ca96...