Setting predefined value on newly created form

Dotychczas
Mega Guru

Hello experts, 

I'm trying to create new record from related list and set some predefined values on the form. I copied "New" ui action:

find_real_file.png

in line 8 I'm trying to set value of audit field but after running this ui action I get info message saying "Record not found". What am I doing wrong?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

don't update OOB ui action

you can use onLoad client script or display business rule on that related list table and set the audit field

onLoad client script on that related list table

function onLoad(){

	var url = top.location.href;
	if(g_form.isNewRecord() && url.indexOf('sys_is_related_list=true') > -1){
		g_form.setValue('audit', '18603524db7830509507a15505961943');
	}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

15 REPLIES 15

@Dotychczas 

this should give you the url and it should contain the parameter

var url = top.location.href;

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Dotychczas 

Glad that you got the solution.

Did you mistakenly marked other response as correct?

The approach of determining the url and using onLoad client script was shared first by me.

You can mark only 1 response as correct.

I am not against marking other response as correct

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The other guy pointed out that Isolate script need to be unchecked but you are right you well deserved it.

Kind Regards

This is strange actually. Sharing a script but did that got you to a solution will be something to check before marking the answer as correct.

I am also not against marking the other response as correct here, just sharing my view on this.

Leaving up to you to decide the best here as there can be only 1 solution.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

shloke04
Kilo Patron

Hi @Dotychczas 

Please use the script below which is a tested one and works great in my PDI.

Please write a On Load Client Script on the Table where you want to set the value or prefill it.

function onLoad() {
   //Type appropriate comment here, and begin script below
   var getURL = window.location.href;
	alert(getURL);
	
	if(g_form.isNewRecord() && getURL.indexOf('sys_is_related_list=true')>-1){
		g_form.setValue('short_description','test');
	}
}

Make sure to uncheck "Isolate field" checkbox on Client script form as shown below:

find_real_file.png

This should work for you as well and set the fields you want.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke