Hello community!

I need to set fields required based in values of a lookup at client side.

I was trying to test how isRequired works in attributes , but I found that the only way to work with it, is declaring the explicit value to True or False.

Tried to use a virtual column, and a method function, but it behaves weird.  

Here are my examples:

and this how it looks on screen:

 

It's showing the "Enter a Value" warning but they are supposed not to be required (* is missing).

 

Is there any way to workaround with this?

 

Thank you for your help.

Like 0

Like

3 comments
Best reply

Cesar Jaramillo,

Let's see what method of making fields required* dynamically actually works good – it is using rules/businessRules.
You can create a rule for your field, the condition can be any value of the page and its related lookups.
Like here:

But if you have to do this for several fields, it will take much time to set them for each field. 
And if there are many conditions or they are too complex, "businessRules" abilities can be not enough.
But we can set an attribute (boolean) to be a condition for each of these rules, like here:

The attribute value can be changed dynamically using "methods".

 

So here's what i'd advise you to do:

In my example the fields "Email" and "Preferred language" become required, if the contact Type is "Customer" and the "Owner" field is not empty.
1. Add an attribute of type BOOLEAN

attributes: {
	"FullInfoRequired": {
		"dataValueType": Terrasoft.DataValueType.BOOLEAN,
		"dependencies": [
			{
				"columns": ["Owner", "Type"],
				"methodName": "setFullInfoRequired"
			}
		]
	}
},

Each time any of the columns ("Owner" or "Type") is changed, the method "setFullInfoRequired" is called.

2. Add the method

setFullInfoRequired: function() {
	var type = this.get("Type");
	// ContactType.Client is a GUID for "Customer" type
	if (type.value === confConsts.ContactType.Client && this.get("Owner")) {
		this.set("FullInfoRequired", true);
	}
	else this.set("FullInfoRequired", false);
}

To set the attribute on page loading, immediately after the page loaded its data, you should also call this function in "onEntityInitialized":

onEntityInitialized: function() {
	this.callParent(arguments);
	this.setFullInfoRequired();
}

3. Add the rules using Page designer, as in my 2nd screenshot, for each field that should become required.

 

If the conditions are simple, just use businessRules as in the 1st screenshot.

 

Hello Cesar,

 

The isRequired attribute that uses the value that method returns works correctly in my local app (using bindTo: {"method name here"}). It seems that there is either some other custom logic related to these columns in the ContactPageV2 or maybe custom CSS that hides these * symbol. You need to look through all the logic related to these columns where you need to have the * symbol.

 

Best regards,

Oscar

Oscar Dylan,

Hi Oscar,  In my case, when the method returns True it works fine, but when it returns False, the * is gone, but the warning remains and it doesn't allow to save.  In what version did you try it?

Thanks!

Cesar Jaramillo,

Let's see what method of making fields required* dynamically actually works good – it is using rules/businessRules.
You can create a rule for your field, the condition can be any value of the page and its related lookups.
Like here:

But if you have to do this for several fields, it will take much time to set them for each field. 
And if there are many conditions or they are too complex, "businessRules" abilities can be not enough.
But we can set an attribute (boolean) to be a condition for each of these rules, like here:

The attribute value can be changed dynamically using "methods".

 

So here's what i'd advise you to do:

In my example the fields "Email" and "Preferred language" become required, if the contact Type is "Customer" and the "Owner" field is not empty.
1. Add an attribute of type BOOLEAN

attributes: {
	"FullInfoRequired": {
		"dataValueType": Terrasoft.DataValueType.BOOLEAN,
		"dependencies": [
			{
				"columns": ["Owner", "Type"],
				"methodName": "setFullInfoRequired"
			}
		]
	}
},

Each time any of the columns ("Owner" or "Type") is changed, the method "setFullInfoRequired" is called.

2. Add the method

setFullInfoRequired: function() {
	var type = this.get("Type");
	// ContactType.Client is a GUID for "Customer" type
	if (type.value === confConsts.ContactType.Client && this.get("Owner")) {
		this.set("FullInfoRequired", true);
	}
	else this.set("FullInfoRequired", false);
}

To set the attribute on page loading, immediately after the page loaded its data, you should also call this function in "onEntityInitialized":

onEntityInitialized: function() {
	this.callParent(arguments);
	this.setFullInfoRequired();
}

3. Add the rules using Page designer, as in my 2nd screenshot, for each field that should become required.

 

If the conditions are simple, just use businessRules as in the 1st screenshot.

 

Show all comments

In an edit page, we have fields that can be changed by the user or calculated by the page Javascript code, depending on specific circunstamces.

In this case we need to inhibit the attribute dependency method call, to make sure it is not called when the field is calculated by the page code, and not by the user.

Is it possible ?

Regards,

Like 0

Like

3 comments

Hi Ricardo,

 

Everything is simple - these specific circumstances should be included into the logic of custom method calls inside the JavaScript code. So the logic itself should be redesigned.

 

Best regards,

Oscar

Oscar Dylan,

Ok, but what I am looking for is a way of disabling the handler method activation in the attribute dependency, so that when the field is updated by the code the handler method will not be triggered... The Javascript code would first disable the dependency method call, update the field, and then enable the dependency control again.

Ricardo Bigio,

One way to accomplish that is to add a property or attribute to the code where you can set a flag that the field is being updated via code, then in the event handler, check this flag to see if you should exit or continue The flag would only get set by code, so the user entering a value the flag won't be set and the event handler will trigger normally. Something like this:

suppressEvent: false,
 
funcThatSetsDependentColumn: function() {
    this.suppressEvent = true; // set flag to suppress the event
    this.set("UsrDependentColumn", value); // set the column that will trigger the event
},
 
dependentColChangeHandler: function() {
    // check if flag is set to suppress the event
    if (this.suppressEvent) {
        this.suppressEvent = false; // unset the flag and exit
        return;
    }
 
    // do other stuff in the event handler here
}

Hope this helps,

Ryan

Show all comments

Changes on attributes dependencies are not being triggered on my detail edit page. Any reason for that ?

regards,

Like 0

Like

1 comments

Ricardo,

 

It's really hard to understand the issue completely without the code of the detail edit page and without the logic that the code represents. Can you please provide us with it?

 

Best regards,

Oscar

Show all comments

Dear Community,

I was wondering if there's a comprehensive list somewhere where we can find all the attributes for the schema page.
Some of the examples are:
- In diff we can add different things like

"operation": "delete",
                    "name": "",
                    "propertyName": "",
                    "parentName": "",
                    "values": {}
Where can I find a list of things I can put in the Diff and "values"?
Same thing for messages, attributes, ...

Thank you in advance!

Like 0

Like

3 comments

Hi Yosef,

 

You can find the chain of articles here that describes multiple schema configurations:

https://academy.creatio.com/documents/technic-sdk/7-16/introduction-3

The diff array article among others describes the possbile operations that you refer to

https://academy.creatio.com/documents/technic-sdk/7-16/diff-array

 

Regards,
Dean

dean parrett,

Thank you for the quick response but this isn't exactly what I'm looking for, it sure is a great start for beginners!

What I'm looking for is like an "extended" list. If I want to enable or disable an item, I would be adding the ' "enable": true ' to the diff. This is nowhere to be found on the second link.

While programming I found bits and pieces of information of these properties in different posts, but I'm looking for something more complete in one place.

If anyone knows or has made a list like this, please let me know!
Thank you

Show all comments

Can we add columns of an object to be selected in a custom lookup, similar to the data validation lookup? 

For e.g. in one lookup, can I have column Name, object and attribute where object = contact and attribute will have values as the columns in contact object.

Like 0

Like

1 comments

Dear Krishna, 

The mentioned data entry compliance lookup and it's functionality is build upon a few separate objects in "Completeness" package. 
In order to create the same lookup or implement the similar functionality you will have to check objects and pages from this package and create a new object with the same parameters upon which the new lookup will be created. 

Kind regards,
Roman

Show all comments

Hello, 

 

I am trying to edit the schema for a page (Quotes) to grab the connected project's contact and account names with the attribute and method properties.

 

So far my code is grabbing the name, but it is not being set correctly. As well, the contact title for the page is disappearing when I add the attribute.KwlContact bit 

Hello, 

 

I am trying to edit the schema for a page (Quotes) to grab the connected project's contact and account names with the attribute and method properties.

 

So far my code is grabbing the name, but it is not being set correctly. As well, the contact title for the page is disappearing when I add the attribute.KwlContact bit 

 

This is the result:

 

If I comment out the  attribute.KwlContact bit I get this:

 

What am I missing to get this code to work?

Like 0

Like

Share

1 comments

Dear Philip,

First. An attribute doesn't know what is "onChanged" property. To launch a method when an attribute is changed use "dependencies" property:

 attributes: {
            "KwlContactName": {
                "dataValueType": this.Terrasoft.DataValueType.TEXT,
                "type": this.Terrasoft.ViewModelColumnType.ENTITY_COLUMN,
                "columnPath": "KwlProject.Contact.Name",
                "caption": {bindTo: "Resources.Strings.KwlContactCaption"},
                "dependencies": [
                    {
                        "columns": [ "KwlProject" ], // columns that trigger a call
                        "methodName": "onSomePropertyChanged"
                    }
                ]
            }
        },

Second. You cannot write project["Contact.Name"] because project variable doesn't have anything but value and display value fields. You should use client EntitySchemaQuery to read new contact name and set it to KwlContactName in async way.

Third. It seems you have an issue with localizable string. Maybe it doesn't exist or you didn't specified a value for language of user's profile.

Show all comments