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.