- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 02:37 AM
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:
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 03:44 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 05:04 AM
this should give you the url and it should contain the parameter
var url = top.location.href;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 05:06 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 05:40 AM
The other guy pointed out that Isolate script need to be unchecked but you are right you well deserved it.
Kind Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 05:46 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 04:48 AM
Hi
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:
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
Regards,
Shloke