Validation on widget

Hafsa1
Mega Sage

I have a custom widget where we are using 1 input field from user table using record-picker.

"<sn-record-picker field="com_id" table="'sys_user'" display-field="'user_name'" value-field="'sys_id'" search-fields="'user_name'" page-size="100" default-query="'active=true'"></sn-record-picker>"

And after selecting others fields, it create record in 1 custom table "sn_hr_core_profile_master"

I want that if next time any user select same employee and if for him already record created and isactive then it should not submit it and through error that record already exists for user name "user_name".

How can i achive it.

 

 

1 ACCEPTED SOLUTION

Harshal Aditya
Mega Sage
Mega Sage

Hi @Hafsa1 ,

 

Hope you are doing well,

 

Please refer to the script below -

 

HTML

 

<div>
<sn-record-picker field="com_id" table="'sys_user'" display-field="'user_name'" value-field="'sys_id'" search-fields="'user_name'" page-size="100" default-query="'active=true'"></sn-record-picker>
</div>

 

 

Client

 

api.controller=function($scope) {
  /* widget controller */
  var c = this;
	c.data.user = "";
	$scope.com_id={
		displayValue:c.data.user_name,
		value:c.data.sys_id,
		name:"user"
	};
	$scope.$on("field.change",function(event,param){
		c.data.user = $scope.com_id.value;
		c.server.update();
	})
						 
						 
};

 

 

Server

 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	if(input)
	gs.addErrorMessage(input.user);
	// Use Glide Record to check if request raised

})();

 

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

View solution in original post

5 REPLIES 5

Hafsa1
Mega Sage

Thanks got it