Client Script to control the state choice of task

Kumar_a43
Tera Contributor

How to write client script to control the state choice option for task table 

It should behave like below -

-show work in progress when task is open

-show other state when the task is work in progress except open

3 REPLIES 3

DonaldSlack
Tera Contributor

I feel your pain, ChadLee4! As of now, there isn't a way to directly map attachments to specific fields in the portal. However, I've seen some discussions on the ServiceNow community about potential future enhancements for this functionality. Maybe subscribing to relevant forums or keeping an eye on release notes could be helpful.

Brad Bowman
Kilo Patron
Kilo Patron

Use remove option in an onLoad Client Script with caution - applying this to the task table will affect extended tables that you may not want to do this on - incident, problem, change, request, requested item, and like 60 other tables, so better to apply it directly to whatever table(s) you want to have this behaviour.

 

https://docs.servicenow.com/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/Glid...

 

You would need a similar script onChange to handle the State field changing whilst a record is displayed. 

 

Bert_c1
Kilo Patron

hmm, I tried an onload client script defined on task. And I don't see it running when I open an incident record or other child table. The following works in limited testing of a few records. 

 

//-show work in progress when task is open
//-show other state when the task is work in progress except open
function onLoad() {
	var stateVal = g_form.getValue('state');
	alert("Task state client script. state = " + stateVal);
	if (stateVal == '1') {
//		alert('state is 1');
		g_form.removeOption('state', '3');
		g_form.removeOption('state', '-5');
		g_form.removeOption('state', '4');
		g_form.removeOption('state', '1');
		g_form.removeOption('state', '7');
	}
	if (stateVal == '2') {
//		alert('state is 2');
		g_form.removeOption('state', '1');
	}
}

And as @Brad Bowman  states, you may want an onChange client script based on your goal.