Hi community,

 

I try to display (or not) an element based on information found on the contact page of the connected user. I tried with a business rule but I only can choose the user connected and not its related objects and their attributes.

 

So I tried something like that in the methods :

		methods: {
			init: function() {
				this.callParent(arguments);
				this.mixins.MultiChoiceMixin.init.call(this, arguments);
				// console.log(this.checkIfInHR());
				},
			/** 
			* Check if connected user is in HR department
			* @param  {string} departmentId  The contact's department Id
			* @param  {string} contactTypeId The contact's type Id
			* @return {bool} 			true if user is in HR department, otherwise false
			*/
			checkIfInHR: function(departmentId = "", contactTypeId = ""){
 
				// if called without args, query connected contact
				if (departmentId == "" && contactTypeId == ""){
					var esq = Ext.create("Terrasoft.EntitySchemaQuery", {rootSchemaName: "Contact"});
 
					// query the contact's department and contact's type
					esq.addColumn("Department");
					esq.addColumn("Type");
 
					// Execute the query 
					esq.getEntity(Terrasoft.SysValue.CURRENT_USER_CONTACT.value, function(res) {
						if (res.success){
							// call checkIfHR again but with args this time
							this.checkIfHR(res.entity.values.Department.value, res.entity.values.Type.value);
						}}, this);
				} else {
					// if args are passed
					// console.log() will be removed in prod
					console.log("departmentId : ", departmentId);
					console.log("contactTypeId : ", contactTypeId);
					console.log("response : ", departmentId == "ca611978-6277-4576-8a96-22ae54fe4d79" && contactTypeId == "60733efc-f36b-1410-a883-16d83cab0980");
					// 1st Id : HR department, 2nd Id: Our company
					return departmentId == "ca611978-6277-4576-8a96-22ae54fe4d79" && contactTypeId == "60733efc-f36b-1410-a883-16d83cab0980";
				}
			}
		}

Then I tried to call this method in the DIFF part :

			{
				"operation": "insert",
				"name": "Tab0f271a37TabLabel",
				"values": {
					"caption": {
						"bindTo": "Resources.Strings.Tab0f271a37TabLabelTabCaption"
					},
					"items": [],
					"order": 11
				},
				"parentName": "Tabs",
				"propertyName": "tabs",
				"index": 10,
				"enabled": this.checkIfInHR()
			},

but it always gives me this error now:

Uncaught TypeError: this.checkIfInHR is not a function

 

Do you have a better way to hide a tab based on values in the user connected' contact page or a way to fix my error ?

 

Best regards,

 

Julien G.

Like 0

Like

3 comments
Best reply

Hi Julien,

 

I cannot see the checkIfInHR method call on the init method execution, but I suppose you wanted to call it inside the "enabled" property of the Tab0f271a37TabLabel object. Ok, but the problem is that you need to use:

"enabled": {"bindTo": "checkIfInHR"},

and also the "enabled" property should be initialized inside the "values" object. So the code should've been:

onEntityInitialized: function() {
				this.callParent(arguments);
				this.mixins.MultiChoiceMixin.init.call(this, arguments);
				this.checkIfInHR();
				},
 
....
 
{
				"operation": "insert",
				"name": "Tab0f271a37TabLabel",
				"values": {
					"enabled": {"bindTo": "checkIfInHR"},
					"caption": {
						"bindTo": "Resources.Strings.Tab0f271a37TabLabelTabCaption"
					},
					"items": [],
					"order": 11
				},
				"parentName": "Tabs",
				"propertyName": "tabs",
				"index": 10
			},

The next problem is that this approach won't work since there is no "enabled" property for tab labels. So the general approach should be modified.

 

I would suggest using this check in the onEntityInitialized method:

onEntityInitialized: function() {
				this.callParent(arguments);
				this.mixins.MultiChoiceMixin.init.call(this, arguments);
				this.reformTabsCollection();
			},
			reformTabsCollection: function(){
				this.checkIfInHR();
				var tabsCollection = this.get("TabsCollection");
				if (this.get("BooleanAttribute")==false) {
                        tabsCollection.removeByKey("TheTabYouNeedToBeNotVisible");
                    }
			}

Also you need to create some bool attribute where the result of the checkIfInHR method will be written (using this.set("BooleanAttribute", true) or this.set("BooleanAttribute", false) at the end of the checkIfInHR method execution based on the checkIfInHR method results). There is no need to store the tab on the page in case it should be non clickable.

 

Best regards,

Oscar

Change it from this:

"enabled": this.checkIfInHR()

To this (and move inside of "values"):

"enabled": { "bindTo": "checkIfInHR" }

Ryan

Hi Julien,

 

I cannot see the checkIfInHR method call on the init method execution, but I suppose you wanted to call it inside the "enabled" property of the Tab0f271a37TabLabel object. Ok, but the problem is that you need to use:

"enabled": {"bindTo": "checkIfInHR"},

and also the "enabled" property should be initialized inside the "values" object. So the code should've been:

onEntityInitialized: function() {
				this.callParent(arguments);
				this.mixins.MultiChoiceMixin.init.call(this, arguments);
				this.checkIfInHR();
				},
 
....
 
{
				"operation": "insert",
				"name": "Tab0f271a37TabLabel",
				"values": {
					"enabled": {"bindTo": "checkIfInHR"},
					"caption": {
						"bindTo": "Resources.Strings.Tab0f271a37TabLabelTabCaption"
					},
					"items": [],
					"order": 11
				},
				"parentName": "Tabs",
				"propertyName": "tabs",
				"index": 10
			},

The next problem is that this approach won't work since there is no "enabled" property for tab labels. So the general approach should be modified.

 

I would suggest using this check in the onEntityInitialized method:

onEntityInitialized: function() {
				this.callParent(arguments);
				this.mixins.MultiChoiceMixin.init.call(this, arguments);
				this.reformTabsCollection();
			},
			reformTabsCollection: function(){
				this.checkIfInHR();
				var tabsCollection = this.get("TabsCollection");
				if (this.get("BooleanAttribute")==false) {
                        tabsCollection.removeByKey("TheTabYouNeedToBeNotVisible");
                    }
			}

Also you need to create some bool attribute where the result of the checkIfInHR method will be written (using this.set("BooleanAttribute", true) or this.set("BooleanAttribute", false) at the end of the checkIfInHR method execution based on the checkIfInHR method results). There is no need to store the tab on the page in case it should be non clickable.

 

Best regards,

Oscar

Oscar Dylan,

 Thank you very much !

 

Best regards,

 

Julien

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

Hi,

is it possible to apply filters to the addRecord button? If so, how can i apply them and execute methods when pressing it.

This print shows the section page with the addRecord button "Novo".

Like 0

Like

1 comments

Dear Pedro,

In order to apply filters to the “addRecord” button please do the following:

1. Create a replacing client schema module. Please find more information in the article by the link below:

https://academy.creatio.com/documents/technic-sdk/7-15/creating-custom-client-module-schema

2. Set “Parent object” property to “Base data view” value https://prnt.sc/psavyp

3. Use the following code as an example:

define("BaseDataView", [], function(){

return{

                messages: {},

                mixins: {},

                methods: {                                         

                // new custom method

                TestMethod: function(){

                                return true;

                },

                // overriding addRecord method

                addRecord: function(typeColumnValue){

                var schema = this.getEditPageSchemaName(typeColumnValue);

                if(schema === "AccountPageV2"){

                                // use here your methods or filters

                                this.TestMethod();

                                }

                this.callParent(arguments);

                }

                },

                diff: /**SCHEMA_DIFF*/ [] /**SCHEMA_DIFF*/

                                };

});

 

Please find more information about filters in the article by the links below:

https://academy.creatio.com/documents/technic-sdk/7-14/entityschemaquery-class-filters-handling?_ga=2.100001118.1940880110.1572861922-1199877090.1572861922

https://academy.creatio.com/documents/technic-sdk/7-13/entityschemaquery-filters-handling?_ga=2.5228019.1940880110.1572861922-1199877090.1572861922

4. In case, if it is need to apply a filter only for particular sections, please add a name of these sections to the following part of code:

if(schema === "Section name"){

// use here your methods or filters

                this.TestMethod();

}

 

Please note that it is possible to find the name of the particular section in the query string. For example, for Account section the name is “AccountSectionV2”. Please see the screenshot below:

https://prnt.sc/psb2jp

 

Best regards,

Norton

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