Hi Community,

 

I am trying to add a field validation via javascript code using the below article.

https://academy.creatio.com/docs/developer/getting_started/develop_appl…

 

While I am trying the validation, I am getting an error in the console as in the screenshot below. It says "Cannot read properties of undefined (reading 'invalidMessage')." I am initiating a null value in the method as described in the above article. What am I missing here? I cannot add validation to any fields because of this error. I have also added my code snippet below.

 

onEntityInitialized: function() {
				this.callParent(arguments);
				this.onBooleanChange();
				this.changeColor();
				this.setYearEnd();
				this.setNumberOfDaysInApplicationCreationStage();
				this.accountHolderValidator();
			},
 
			setValidationConfig: function() {
				this.callParent(arguments);
				//this.addColumnValidator("BEALMDateofBirth", this.dateOfBirthValidator);
				this.addColumnValidator("BEALMAccountHolderType", this.accountHolderValidator);
			},
 
			accountHolderValidator: function() {
				var invalidMessage = "";
				var lead = this.get("BEALMLead").value;
				var scope = this;
				var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
					rootSchemaName: "Lead"
				});
				esq.addColumn("Id");
				esq.addColumn("BEALMIsPAHExist");
 
				var esqFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Id", lead);
				esq.filters.add("esqFilter", esqFilter);
 
				esq.getEntityCollection(function (result) {
					if (result.success) {
						var isPAHExist = result.collection.collection.items[0].values.BEALMIsPAHExist;
						if (isPAHExist == true) {
							invalidMessage = this.get("Resources.Strings.BEALMInvalidAccountHolderMessage");
						}
						else {
							invalidMessage = "";
						}
						return {
							invalidMessage: invalidMessage
						};
					}
				});
			},

 

Please help to resolve this issue.

 

Thank you

Cheers!

Like 0

Like

2 comments
Best reply

There are two issues:

1) You're not including the scope in your ESQ so in the callback it no longer knows what "this" is. Change to this: 

esq.getEntityCollection(function (result) {
    // stuff here
}, this);  // <- notice passing this scope 

2) Regardless of the missing "this" scope, this will not work since the ESQ is asynchronous. You'll need to use asyncValidate instead. I have an article on how to do that here: https://customerfx.com/article/asynchonous-validation-on-pages-in-creat…

Ryan

 

There are two issues:

1) You're not including the scope in your ESQ so in the callback it no longer knows what "this" is. Change to this: 

esq.getEntityCollection(function (result) {
    // stuff here
}, this);  // <- notice passing this scope 

2) Regardless of the missing "this" scope, this will not work since the ESQ is asynchronous. You'll need to use asyncValidate instead. I have an article on how to do that here: https://customerfx.com/article/asynchonous-validation-on-pages-in-creat…

Ryan

 

Hi Ryan,

 

Thank you very much for the support. That worked like a charm.

Show all comments

Hello Community, 

 

I have a requirement to validate a Column in the editable detail.

How can we achieve this? I tried using validators with the column name of Datagrid. But it didn't worked.

 Any suggestions is really helpful. 

 

Thanks

Gargeyi.G

File attachments
Like 0

Like

3 comments

Hello,

In order to add validation to an editable detail you need to override the method save() in the detail page, for example:

define("UsrSchema1051cea3Page", [], function() {
	return {
		entitySchemaName: "UsrTestDetObj",
		attributes: {},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			save: function() {
                    if (this.get("UsrName") == "1") {
                        this.callParent(arguments);
                    } else {
                        this.showInformationDialog("UsrName should be 1 ");
                    }
                }
		},
		dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
	};
});

 

Hello, 

 

Thankyou for your response, 

But I wanted to validate columns in the detail,

I don't open the detail page and so I don't want to validate in the detail page but in the inline record.

please find attached screenshot

Hi,

This example is working on a detail itself.

With it, you cannot save the record unless the condition is met.

Considering the fact that detail fields are virtually generated, this is the best option to add validation.

Show all comments

Is it possible to change the Location of Validation message in Screen ? 

Please See the screenshot. I want to Change the place of the message from bottom to right as this message is covering the Bellow field's text.

Like 0

Like

1 comments

Hello,

 

Thank you for reporting this issue to us!

 

Unfortunately, the described behavior cannot be improved with a help of basic system tools as of now, but we have already registered a query for our responsible R&D team to improve this functionality in the upcoming releases of the main application. 



Thank you for helping us to make our application better!



Best regards,

Anastasiia

Show all comments

 

Like 1

Like

1 comments
Best reply

Hello Jerome,



The behavior you describe is not an error and corresponds to the basic logic that is inherent in all fields. If the field has the "Required" property and the field type is Number or Fractional, then a value of 0 or 0.00 is an empty value, that is, the field is not filled. Thus, when you try to save a card with 0.00 in a numeric field with the required property, the system will display a message that the field must be filled with a value. The values ​​0 or 0.00 is an empty values, they are displayed in empty fields so that users can visually understand the format of the field. We recommend you remove the mandatory filling from the required field so that you can save the card with a zero value in the field. We will broadcast the information received from you to the development team to consider the possibility of changing the logic of the mandatory filling of numeric fields.



Best Regards,

Kate

Hello Jerome,



The behavior you describe is not an error and corresponds to the basic logic that is inherent in all fields. If the field has the "Required" property and the field type is Number or Fractional, then a value of 0 or 0.00 is an empty value, that is, the field is not filled. Thus, when you try to save a card with 0.00 in a numeric field with the required property, the system will display a message that the field must be filled with a value. The values ​​0 or 0.00 is an empty values, they are displayed in empty fields so that users can visually understand the format of the field. We recommend you remove the mandatory filling from the required field so that you can save the card with a zero value in the field. We will broadcast the information received from you to the development team to consider the possibility of changing the logic of the mandatory filling of numeric fields.



Best Regards,

Kate

Show all comments

We are looking for a for a way to impose a character limitation on a string value that is different than the standard settings. 

 

For example, the user enters a job number as a string and we want to restrict entry to only 10 characters. Is there a way to do this? Obviously not OOTB but with some customization?

Like 0

Like

1 comments

There is a possibility to setup a field validation and this approach is described in this Academy article.

 

Best regards,

Oscar

Show all comments

Hi All,

I need to put validation to restrict the lookup column "Name" to a certain number of characters(not 50,250,500). Can anyone suggest how can i achieve that?

Like 1

Like

3 comments
Best reply

Hello rajat,

 

You can add an event on the object itself through the configuration:

https://prnt.sc/LIjTKY0mxzdz

 

Get the value of the Name field and make sure that it isn't longer than x characters.

 

 

Kind regards,

Yosef

Hello rajat,

 

You can add an event on the object itself through the configuration:

https://prnt.sc/LIjTKY0mxzdz

 

Get the value of the Name field and make sure that it isn't longer than x characters.

 

 

Kind regards,

Yosef

Hi yosef,

I am not able to add anything in that business process. Can you guide me how  to achieve the above objective

 

rajat patidar,

 

Make sure the object exists in your package (custom package is the default one) and then use an event subprocess.

Here's an example on how to work with server side code:

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/add_auto_numbering_to_the_field#title-1349-12

 

You can then follow this logic:

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/add_the_field_validation

 

 

Kind regards,

Yosef

Show all comments

Hello

 

I was trying to validate email format and phone number format in activity section in mobile application but could not find anything.

Please provide me a way to validate these fields in mobile application.

 

Regards,

Malay

Like 0

Like

5 comments

Hello Malay,



Could you please provide us more detailed information on your business task? Could you share screenshots?



Thank you in advance!

 

Best regards,

Bogdan

Hello Bogdan,

 

Hello I want to apply validation for mobile number and email in activity section. For example, the phone number should be of 10 digits and only contain numbers and email format should be of the form abc@xyz.com.

 

I have used JavaScript for lead section to do it for the web version but how to do it for the mobile application?

 

Below is the screenshot of the mobile activity page where I want to apply this validation.

 

Regards,

Malay

Hello Malay,

You can use a custom business rule for this task. See here for an example: https://academy.creatio.com/docs/developer/mobile_development/mobile_ap…

For using the custom rule for validation, you can pass a third parameter to the callback function with a message (the validation message) and value (true or false indicating if validation passed or not).

For example:

var result = {};
if (passedTheTestAndIsValid) {
    result = {
        value: true
    };
}
else {
    result = {
        value: false,
        message: "The entered value is invalid"
    }
}
 
// now include the result in the callback
Ext.callback(callbackConfig.success, callbackConfig.scope, [result]);

Ryan

Ryan Farley,

 Thanks for share it. You have any example using esq query in custom business rules for validations?

Christian Kern,

 

1. File will be stored in configurations.

 

2. The main rule - the first word of business rule name should be the section name. Like "Contact", "Case", "Account". 

 

Best regards, 

 

Bogdan L.

Show all comments

Hi,



So have this default Opportunity Section which we edited to change the UI for creating a New Record (see image for reference). Then we change it in a way that choosing customer can only be through accounts, which we are having the prompt error actually.







Question

After checking all the previous version of OpportunityPageV2, I can't find anything that prompts this error, any thoughts/comments?

Like 0

Like

2 comments
Best reply

Hi,



I'm able to afford to fix my problem via the following code segment. I both declared this in minipage and pagev2 of opportunity.

          "Client": {
            "caption": {"bindTo": "Resources.Strings.Client"},
            "dataValueType": Terrasoft.DataValueType.LOOKUP,
            "multiLookupColumns": ["Account"],
            "isRequired": false
          },

Thanks a lot!

Hello Solem,

 

Hope my message finds you well.

 

You can check the Opportunity object and find the 'Customer' column, then disable the requirement for this field to be populated. Also, you can use Section Wizard / Page Designer to find the configuration for the mentioned column. Additionally, if you use the mini-page for the Opportunity section, there also need to disable the requirement for the Customer field.

 

Best regards,

Roman

Hi,



I'm able to afford to fix my problem via the following code segment. I both declared this in minipage and pagev2 of opportunity.

          "Client": {
            "caption": {"bindTo": "Resources.Strings.Client"},
            "dataValueType": Terrasoft.DataValueType.LOOKUP,
            "multiLookupColumns": ["Account"],
            "isRequired": false
          },

Thanks a lot!

Show all comments

Hi Team,



I would like to prevent selecting the future date in the date field.

Kindly help me with any insight on this.



Note: All the future date should be greyed out and is not able to select (if it is clicked it shouldn't be selected or populated in the date field).

 

 

 

Thanks in Advance!



Regards,

Bhoobalan P.

Like 0

Like

3 comments

Hi Bhoobalan,

 

Please use the column validator instead that will do the same task:

setValidationConfig: function() {
              this.callParent(arguments);
              this.addColumnValidator("UsrDatetime1",this.dateTimeColumnValidator);
            },
          	dateTimeColumnValidator: function(){
              console.log(this.get("UsrDatetime1"));
              var invalidMessage = "";
              console.log(this.getSysDefaultValue(Terrasoft.SystemValueType.CURRENT_DATE_TIME));
              if (this.get("UsrDatetime1")>this.getSysDefaultValue(Terrasoft.SystemValueType.CURRENT_DATE_TIME)){
               	invalidMessage = this.get("Resources.Strings.ErrorMessage");
              } 
                return {
                  invalidMessage: invalidMessage
                };
              },

Just replace the UsrDatetime1 column with your date\rime column name and also create a localizable string with the "ErrorMessage" code.

 

Best regards,

Oscar

Oscar Dylan,

Thanks much for the precious response!



But still we could select the future date value, And after validation we throw a error message below the corresponding field name. 



We need to block selecting the future date, which could be possibly achieved via Jquery as below,

$("#dateField").datepicker({

    maxDate: 0

});



How could we achieve the same in our CREATIO Date field ?





Regards,

Bhoobalan P.

Bhoobalan Palanivelu,

 

This validator will also return a validation message upon saving a record with an incorrect date, so it's not possible to select the date\time grater than the current date\time:

And this is much easier than creating a custom logic for the date selector modal window so please use this approach.

 

Best regards,

Oscar

Show all comments

I am trying to implement validation logic in client module edit page of a section.

I want to save the column value of UsrAttributeName (a lookup) into a variable.

To do this, I am using this.get("UsrAttributeName").displayValue. But when Page is loaded it hangs and console shows the error 

message: Uncaught TypeError: Cannot read property 'displayValue' of undefined 

Like 0

Like

2 comments

Hello! 

 

1. To add validation use this.addColumnValidator method in setValidationConfig method.

Please, find the example in the Academy article: https://academy.creatio.com/documents/technic-sdk/7-16/how-add-field-va…

 

2. If the column value is not defined you cannot call for its properties. Check if the column has value:

var attribute =  this.get("UsrAttributeName");

var attributeDisplayValue = attribute  && attribute.displayValue;

 

Please, let us know in case any additional information is required. 

 

Best regards,

Olga. 

Olga Avis,

Hi 

 

After debugging it turns out undefined is coming because Entity/Page is not fully loaded or when I create a new record then all fields are empty.

I could use your suggested way to assign attribute value to a variable but that would not be able to work if entity/page is not fully loaded.

 

So I used a flag in attributes with default value false and set it to true in OnEntityIntilized method.

Then I checked the flag, if it is true then the validation method will run.

 

Thanks

Ram

Show all comments