Issue with ServicePortal widgets

Revathi Kotha
Tera Contributor

Hello Everyone,

 

How do I update all the select box options to a value when I click on a button on the widget?

HTML

<form name="formName">
 

<div>

 <br/>
  
  
  
  <table border="1px solid black">
     
    <tr>
     
      <th>Employee Number</th>
      <th>Employee Name</th>
      <th>Department</th>
      <th>Division</th>
      <th>End Date</th>
      <th>Action</th>
      
    </tr>
    <tr ng-repeat="x in c.data.arr">
      
      <td>{{x.employee_number}}</td>
      <td>{{x.u_name}}</td>
      <td>{{x.departmentname}}</td>
      <td>{{x.division}}</td> 
      <td>{{x.enddate}}</td>
      <td><select id="manager_action" ng-model="x.manager_action" 
                  class="form-control" ng-change="c.changeAction({{x.employee_number}},x.manager_action)" 
             ng-options="y.name for y in c.data.actions" ng-required="true">   
        </select>  
      </td> 
       
    </tr>  

  </table>
 <button class="test" class="btn btn-primary btn-block" ng-click="c.selectAll()">Keep All</button>
  <br/>
  <br/>
   
</div>
  


Client Script :

api.controller=function($scope,spModal) {
	/* widget controller */
	var c = this;

	c.data.actions=[{
   
		name:'Keep',
		value:'1'

	},
	{
		name:'Remove',
		value:'2'
		
	}]
	
	
	var selectedrecords=[];
	selectedrecords=c.data.arr;

	var employeenumbers=[];
	for(var j=0;j<selectedrecords.length;j++)
	{
		employeenumbers.push((selectedrecords[j].employee_number));
	}
	
	

	c.selectAll=function(rec)
	{
		
	}
	
	
	

	c.changeAction=function(number,actiontaken)
	{

	//	alert(actiontaken);
		c.data.number=number;	
		c.data.action=actiontaken.value;
		$scope.page.g_form.setValue('audited_records',employeenumbers);

		if(number!='')
		{		

			if(actiontaken.value=='2')
			{

				spModal.open({
					title: 'Reason for deactivating CW',
					buttons:[],
					widget: 'cwdeactivation',
					widgetInput: {sys_id:number,action:'Remove'}

				}).then(function(response) {


				});

			}
			else if(actiontaken.value=='1')
			{

				c.server.update();
			}

		}


	}




};

 

 

1 ACCEPTED SOLUTION

Siddhesh Jadhav
Kilo Sage

Hi @Revathi Kotha ,

 

To update all the select box options to a specific value when clicking on the button in your widget, you can modify the selectAll function in your client script to loop through all the items and update the manager_action value.

 

Updated selectAll Function:

c.selectAll = function() {
    for (var i = 0; i < c.data.arr.length; i++) {
        c.data.arr[i].manager_action = c.data.actions[0]; // Set the value to 'Keep' or whichever action you prefer
        c.changeAction(c.data.arr[i].employee_number, c.data.actions[0]);
    }
};


This code will iterate over all the items in c.data.arr and set their manager_action to the value "Keep" (or any action you'd like to assign). The changeAction function is then called to handle the update logic.

 

Thanks & Regards,

Siddhesh Jadhav

 

If this solves your query, please mark it as helpful and accept the solution.

View solution in original post

3 REPLIES 3

Revathi Kotha
Tera Contributor

When KeepAll is selected, how do you update the select box option to a default value, 'Keep'? Attached is the image for reference.

Siddhesh Jadhav
Kilo Sage

Hi @Revathi Kotha ,

 

To update all the select box options to a specific value when clicking on the button in your widget, you can modify the selectAll function in your client script to loop through all the items and update the manager_action value.

 

Updated selectAll Function:

c.selectAll = function() {
    for (var i = 0; i < c.data.arr.length; i++) {
        c.data.arr[i].manager_action = c.data.actions[0]; // Set the value to 'Keep' or whichever action you prefer
        c.changeAction(c.data.arr[i].employee_number, c.data.actions[0]);
    }
};


This code will iterate over all the items in c.data.arr and set their manager_action to the value "Keep" (or any action you'd like to assign). The changeAction function is then called to handle the update logic.

 

Thanks & Regards,

Siddhesh Jadhav

 

If this solves your query, please mark it as helpful and accept the solution.

Revathi Kotha
Tera Contributor

@Siddhesh Jadhav   Thank you so much.It worked. I am new to widgets and struggled to get the value of action .Now I understand that  

c.data.actions[0]

 

The information below helps me get the value.