Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

please let me know any thing worng in my script becuase i didn't get user_sesstion1 result

mani55
Tera Contributor
api.controller=function($scope,$rootScope,spSCNavStateManager,spUtil) {
  /* widget controller */
  var c = this;
  var min = 1 ;
  var max = '';	
	//$scope.request_type = $scope.page.g_form.getValue('request_type_txt')+'';	
		
	c.server.update().then(function(res){		
			$rootScope.$on("field.change", function(evt, parms) {
				
				var no_of_vdi = $scope.page.g_form.getIntValue('user_session');
			//	var no_of_users = $scope.page.g_form.getIntValue('noofusers');
				//var number_vdi = $scope.page.g_form.getIntValue('No_of_VDI');
		
      //###################################################################
					if (parms.field.name == 'user_session1'){
					var vdi_value =  $scope.page.g_form.getValue('user_session1');	
					if (vdi_value == '') 					
						$scope.page.g_form.setValue('enter_license_count','');		
				}
								
				if(parms.field.name == 'modify_licenses_count' || parms.field.name == 'enter_license_count' ) {
					var value_vdi=	$scope.page.g_form.getDisplayValue('modify_licenses_count');
					var add_vdi= $scope.page.g_form.getIntValue('enter_license_count');				
                    $scope.page.g_form.setValue('user_session1',no_of_vdi);
					
					if(value_vdi =='add_licenses')
					{
						if(parms.field.name == 'modify_licenses_count' || add_vdi > 0) {							
							$scope.page.g_form.setValue('user_session1',no_of_vdi  + add_vdi);
					}
					else 		
                        {
						$scope.page.g_form.clearValue('enter_license_count');
				$scope.page.g_form.showFieldMsg('enter_license_count','The maximum number of Users/device per service is 10 currently.','error');
						}
					}
                   if(value_vdi == 'remove_licenses')
                    {
                      if(parms.field.name == 'modify_licenses_count' || add_vdi > 0)  {
							$scope.page.g_form.setValue('user_session1',no_of_vdi  - add_vdi);
                       }
					else 		
                        {
						$scope.page.g_form.clearValue('enter_license_count');
				$scope.page.g_form.showFieldMsg('enter_license_count','The service should have minimum 1 user/device in active state. To remove all users/devices, you need to retire the service','error');
						}	
                    }
				}}
			)})};
2 REPLIES 2

Abhishek Pal
Giga Guru

@mani55 
The issue is that you are using getDisplayValue() for modify_licenses_count, but comparing it with the internal choice values add_licenses and remove_licenses.

Replace:

var value_vdi = $scope.page.g_form.getDisplayValue('modify_licenses_count');

With:

var value_vdi = $scope.page.g_form.getValue('modify_licenses_count');

This should allow your conditions for add_licenses and remove_licenses to work correctly.          

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
abhishek Pal

yashkamde
Giga Sage

Hello @mani55 ,

 

try fixing this :

var value_vdi = $scope.page.g_form.getValue('modify_licenses_count');

 

also min/max are declared but never used, Your error message says maximum is 10 but nothing actually enforces it.

A user can add 500 and it'll go through silently.

var min = 1;
var max = 10;
...
if(value_vdi == 'add_licenses') {
  var newVal = no_of_vdi + add_vdi;
  if((parms.field.name == 'modify_licenses_count' || add_vdi > 0) && newVal <= max) {
    $scope.page.g_form.setValue('user_session1', newVal);
  } else {
    $scope.page.g_form.clearValue('enter_license_count');
    $scope.page.g_form.showFieldMsg('enter_license_count','The maximum number of Users/device per service is 10 currently.','error');
  }
}

 

If my response helped mark as helpful and accept the solution.