Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to set default value for reference field , only when that field value is empty

kalp
Tera Contributor

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

 

 

15 REPLIES 15

Hi @kalp

 

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

Thanks and Regards
Amit Verma

kalp
Tera Contributor

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.

Hello @kalp  - 

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



kalp
Tera Contributor

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

Hello @kalp - 

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