Help needed when value in referance field changes

Snehal13
Kilo Sage

I have a form on incident table that has a field named 'Region' (referance field with options as US, EU, APAC). There is a UI action button 'Resolve' that shows on this form.

 

(1) If the user selects US & EU, The resolve UI action should be shown

(2) If the user selects APAC, the resolve UI action button should not be shown.

 

How to achieve part (2) from client script.

6 REPLIES 6

Vishal Birajdar
Giga Sage

Hello @Snehal13 

 

This Community link may help...!!

 

https://www.servicenow.com/community/developer-forum/how-to-hide-ui-action-based-on-field-change-in-...

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

That code is jQuery which is DOM manipulation.

RAMANA MURTHY G
Mega Sage
Mega Sage

Hi,

Please try below onChange client script for the Region field (I have tried with the Assignment group field, you can change it according to your requirements. I have tried if assignment group is Database then Resolve button need to be hide, if assignment group is anything else apart from Database, then Resolve button need to be show). But you need to uncheck Isolate script checkbox to run the DOM Manipulation code.

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var uiActionButton = document.getElementById('resolve_incident');   // 'resolve_incident is action name of UI Action button
   if(g_form.getValue('assignment_group') === '287ee6fea9fe198100ada7950d0b1b73'){  // if assignment group is Database
	uiActionButton.style.display = "none";
   }
   else{
	uiActionButton.style.display = "block";
   }
   
}

 

 

 

or you can try this code also

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   if(g_form.getValue('assignment_group') === '287ee6fea9fe198100ada7950d0b1b73'){   // assignment group is Database
	var btn = $$('BUTTON').each(function(item){
		if(item.innerHTML.indexOf('Resolve') > -1){    // 'Resolve' is name of the UI Action button
			item.hide();
		}
	});
   }
   else{
		var btn = $$('BUTTON').each(function(item){
		if(item.innerHTML.indexOf('Resolve') > -1){   // 'Resolve' is name of the UI Action button
			item.show();
		}
	});
   }   
}

 

 

Please mark my answer helpful if it works. 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Not want to do DOM Manipulation to hide UI action based on value change in a referance field. Any other recommended way ? The UI action condition runs on server side and my requirement is to hide UI action when referance field value changes.