How to autopopulate choice if there is single value in reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 11:52 PM
Hi All,
I have created two fields,
Account- Reference
Platform- Reference
Based on Account Platform is giving user to select the record.
But if there is a single record in the Platform then it should be autopopulate.
I tried the below client script on change of Account
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var custReq = g_form.getElement('u_platform');
alert(custReq);
if (custReq.options.length == 1) {
g_form.setValue('u_platform', custReq.options[0].value);
}
}
But it is throwing error "onChange script error: TypeError: Cannot read properties of undefined (reading 'length') function () { [native code] } "
Please help in this.
Thanks,
Sam
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 12:06 AM
@Yashsvi Don't forget to apply best practices and with that the second parameter on reference fields/variables!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 12:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 11:39 PM
