Service Portal - Issue with the selectboxes and the ng-repeat is not working

Revathi Kotha
Tera Contributor

 

Hello All,
When one select box value is selected, the other select box values in the table are changed. Is there anything wrong with the code?

 

HTML
 
 
<td><select id="manager_action" ng-model="c.data.manager_action" class="form-control" ng-change="c.changeAction({{x.employee_number}})" ng-options="y.name for y in data.actions" ng-required="true"> </select> </td>
 
Server Script: data.actions=[{ name:'Keep', value:'1' }, { name:'Remove', value:'2' }]

 

1 ACCEPTED SOLUTION

I'm assuming you want to prevent submission functionality if the required fields are not filled?

 

You need to add a name attribute to the form

<form name="formName">

 

Then check if the form is valid (all required fields are met) when the submit button is clicked

 <button class="test" class="btn btn-primary btn-block" ng-click="c.uiAction('remove')" ng-disabled="formName.$invalid">Keep All</button>

 

View solution in original post

23 REPLIES 23

Revathi Kotha
Tera Contributor

@TFischer  Thank you for assisting me. I am new to widgets and still trying to understand things. I shared the code, and please guide m in the right direction to resolve the issue.

Sharing the server script as well for a better understanding

(function() {
	/* populate the 'data' object */
	/* e.g., data.table = $sp.getValue('table'); */
	//data.manager=$sp.getParameter('manager');
	if(input)
		{
			
			data.empnum=input.empnumber;
			data.act=input.action;
			
			if(data.act=='1')
				{
					var cw=new GlideRecord('u_non_employee');
					cw.addQuery('u_number',data.empnum);
					cw.query();
					if(cw.next())
						{
							cw.u_cw_audit='Reason: Keep'+' audit date: '+gs.nowDateTime();
							cw.update();
						}
				}
		}
	
	data.manager='5a1d6d069750f950d8adb9e3a253af34';
	data.actions=[{
   
		name:'Keep',
		value:'1'

	},
	{
		name:'Remove',
		value:'2'
		
	}]
	
								
	var arr=[];
	var gr=new GlideRecord('u_non_employee');
	gr.addEncodedQuery('u_manager='+data.manager+'^u_in_active=N');
	gr.query();
	while(gr.next())
	{
		var obj={};


		obj.manager=gr.u_manager.toString();
		obj.managername=gr.u_manager.getDisplayValue();
		obj.employee_number=gr.u_number.toString();
		obj.u_requestor=gr.u_requestor.toString();
		obj.requestorname=gr.u_requestor.getDisplayValue();
		obj.department=gr.u_department.toString();
		obj.departmentname=gr.u_department.getDisplayValue();
		obj.division=gr.u_division.toString();
		obj.u_name=gr.u_name.toString();
		obj.enddate=gr.u_enddate_system_format.toString();



		arr.push(obj);



	}

	data.arr=arr;


})();

@Revathi Kotha  A couple things to fix here. We may need to make an additional change to the data formatting, but this should resolve the same select value problem. Here's what the select fields should look like,

 

 

<select id="manager_action" ng-model="x.manager_action" 
             class="form-control" ng-change="c.changeAction(x.employee_number)" 
             ng-options="y.name for y in data.actions" ng-required="true">   
</select> 

 

 

 

There are two changes here,

 

 

 ng-change="c.changeAction(x.employee_number)" 

 

You don't need the {{ }} around variable.

 

 

 ng-model="x.manager_action" 

 

Here we are binding a unique value for all inputs per row. This will likely cause a new console error such as "c.data.manager_action is undefined" but we can fix that by mapping a manager_action key to your data object on the server script. I can help you with this if you are seeing an error and share your server script.

 

 

The model needs be uniquely bound to each object value. Currently, they are sharing a value, which is why the all change when selected.

Thank you so much @TFischer . This line of code 

 ng-model="x.manager_action" 

resolved many of my issues. Also, If I remove braces around the x.employee_number, It's not sending the data to the Client script. One quick question. Why the server.update() in the client script is wiping off other selections in the form. 

When you call server.update() you are re-running the server side script, as if you are loading the server script when the page first loads. Therefore you are most likely going to clear out any updated values unless you add some conditional logic.

I can't be certain without seeing your server script, but you will likely need to add logic to the top of your server script to indicate logic such as "if input is being sent from client, don't re-run script"

 

This can look something like...

 

	if (input && input.action) {
		
		//put logic for handling actions here

	} else {
		
		//put logic to only run on page load here

	}