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

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

if(input)
// Use Glide Record to check if request raised
var grCase = new GlideRecord('sn_hr_core_md_band_nomination_form');
grCase.addQuery('u_candidate', input.user);
var qc = grCase.addQuery('u_state', 'ready');
qc.addOrCondition('u_state', 'draft');
grCase.query();
if (grCase.next()) {
gs.addErrorMessage("Please note that the nomination of this person input.user has been created/submitted");
grCase .setValue('u_candidate','');
}

 

I'm putting this query but it is saying input.user is not defined

Harshal Aditya
Mega Sage
Mega Sage

Hi @Hafsa1 ,

 

Could you please share your client side code that you have written in the widget

Harshal Aditya
Mega Sage
Mega Sage

Hi @Hafsa1  ,

 

c.data.user is not populated in client side that's why input.user is returning undefined in the server side.