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

kalyani23
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 @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.

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 @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



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 @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