setTimeout() function – ServiceNow

Disable one choice list option (which is dependent on another field) based on role

onLoad Script

function onLoad() {
   //var role = g_user.hasRole('Agent');
if(g_form.isNewRecord()){
     setTimeout(function(){
     g_form.removeOption('u_sub_type', 'customer_complaint');
     g_form.removeOption('u_subtask_type', 'customer_complaint');}, 5000); 
//Time in seconds (5 secshere)	
	}   
}

onChange Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
//var role = g_user.hasRole('Agent');
	if(g_form.isNewRecord()){

		setTimeout(function(){
g_form.removeOption('u_sub_type', 'customer_complaint');
g_form.removeOption('u_subtask_type', 'customer_complaint');}, 5000); 
		
		
	}

   //Type appropriate comment here, and begin script below
   
}

Leave a Reply

Your email address will not be published. Required fields are marked *