g_form.getMissingFields() alternative in service portal?

Ahmmed Ali
Mega Sage

Hello All,

Hope all are doing great.

For catalog item in platform view, we can use g_form.getMissingFields() to get mandatory fields which are empty. But I want same functionality in portal, unfortunately above method is does not work in portal. Is there any other way to achieve same?

My use case: I have a button in portal and when I click that button, It should do next task only when there are no mandatory fields on the form which are empty.

 

Also When we try to redirect user to any other URL in catalog form (When user has already filled the form but did not submit), it will popup a alert for confirming to leave current page and data will be lost. How can we avoid the popup. the data will be auto-saved in my use case before redirecting user to another URL. Hence I do not want to show the alert.

 

Thanks

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali
1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

A quick example of a way to check for empty mandatory fields

function filterForMissingMandatoryFields(field){
		//check if field is mandatory
		if($scope.page.g_form.isMandatory(field)){
			//return if there is no value
			return !$scope.page.g_form.getValue(field);
		}
	}

	$scope.getMissingFields = function(){
		//get all fields
		var fieldList = $scope.page.g_form.getFieldNames();

		//return only mandatory fields that have no value
		return fieldList.filter(filterForMissingMandatoryFields)
	}

	//Then call this function when you want to check 
	//$scope.getMissingFields() //this returns an array of empty mandatory fields
	
	//of if calling from an ngClick just do this on the clickable element
	// ng-click="getMissingFields()"

If the return is empty after calling it, it means all mandatory fields are populated.

 

Hope this helps

View solution in original post

7 REPLIES 7

ChrisBurks
Mega Sage

A quick example of a way to check for empty mandatory fields

function filterForMissingMandatoryFields(field){
		//check if field is mandatory
		if($scope.page.g_form.isMandatory(field)){
			//return if there is no value
			return !$scope.page.g_form.getValue(field);
		}
	}

	$scope.getMissingFields = function(){
		//get all fields
		var fieldList = $scope.page.g_form.getFieldNames();

		//return only mandatory fields that have no value
		return fieldList.filter(filterForMissingMandatoryFields)
	}

	//Then call this function when you want to check 
	//$scope.getMissingFields() //this returns an array of empty mandatory fields
	
	//of if calling from an ngClick just do this on the clickable element
	// ng-click="getMissingFields()"

If the return is empty after calling it, it means all mandatory fields are populated.

 

Hope this helps

Thanks Chris

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

kkingsle
Tera Expert

Does anyone know if there is also an equivalent for AgentWorkspace (specifically a UI action).   g_form.save() works, but getMissingFields does not.

 

In my use case, we're launching a modal window to collect more data before proposing a major INC but only want it to complete if all mandatory fields are complete on the form.    The save will validate, but we can't come up with a condition to stop it from proceeding to the modal code.