How to set default value for reference field , only when that field value is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 10:17 PM
Hi ,
I want to set default value in parent field (type reference), only when the field value is empty.
i have given this below code line :
javascript:current.parent= current.parent_activity.parent.toString();
but looks like not working .
Can anyone help with this code.
Thanks in advance
Kalyani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:08 PM
Hi @kalyani23
I am still not very sure about your requirement but I think it could be achieved through Auto Populate feature. Refer https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:27 PM
Hi Amit ,
i could not find the auto-populate feature. i am trying to set default value using dictionary override for task table parent field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:16 PM
Hello @kalyani23 -
Please try using onload Client script, and see if it works.
function onLoad() {
var parentVal=g_form.getValue('parent');
if (parentVal==' ' ) {
var parentActive = g_form.getReference('parent').parent_activity;
g_form.setValue('parent',parentActive);
}
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:19 PM
Hi Pratiksha,
Not preferring onload script in this case , as i have another onload script based on this field value . so it has some conflicts in execution order . so trying to set using default value.
Thanks & Regards,
Kalyani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:30 PM - edited 01-24-2024 11:42 PM
Hello @kalyani23 -
Can you please provide your existing client script code so that we will try to merge both the codes together to avoid the conflict.
Thanks,
Pratiksha