How to show/hide choices of field based on other field on another table?

Deepika61
Tera Contributor

Hi All, 

i have a requirement that in HR task, it has  choice field "HR task type' , so basically i want to display two choices only i.e " process and Leave" when the parent case having "HR service" is Benefits" ?

 

Please help me to resolve this

Thanks

Ramu

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika61 

you can use display BR on HR Task and onLoad client script on HR Task table

Display BR

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.hrService = current.parent.hr_service.name;

})(current, previous);

onLoad client script:

function onLoad(){
	if(g_scratchpad.hrService == 'Benefits'){
		g_form.removeOption('hr_task_type', 'choicevalue1'); // ensure you give correct choice value you want to remove here
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepika61 

you can use display BR on HR Task and onLoad client script on HR Task table

Display BR

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	g_scratchpad.hrService = current.parent.hr_service.name;

})(current, previous);

onLoad client script:

function onLoad(){
	if(g_scratchpad.hrService == 'Benefits'){
		g_form.removeOption('hr_task_type', 'choicevalue1'); // ensure you give correct choice value you want to remove here
	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sandeep Rajput
Tera Patron
Tera Patron

@Deepika61 HR task type field controls how a task should render on Service portal. Since this is an OOTB field which is being used in several script includes please do an impact analysis before applying any customisation on this field.