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

SanjivMeher
Kilo Patron
Kilo Patron

I think you need a onLoad script.

When you click on new, you parent record will already be populated.

 

var pt = g_form.getReference('parent', popParentInfo);
function popParentInfo(pt){

g_form.setValue('short_description', pt.short_description);

g_form.setValue('field2', pt.field2);
}


Please mark this response as correct or helpful if it assisted you with your question.

Thanks for the response.  I am not sure if that is what we are wanting, because we don't want it to lead to a child record, we want the button to lead to a new form on a different table that has not yet been submitted; I might have not explained it well enough with the Child Incident example above, so I edited/clarified what we are looking for.

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

 

You can use this:

 

incident.do?sys_id=-1 // This is URL. Redirect to this when you click on generate. You will see new form which is not submitted.

 

incident.do is just a example. You can use any table you want.


Thanks,

Ashutosh Munot

 

HI,

 

Use this:

 

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

 

Thanks,

Ashutosh Munot