Hi Community,

 

I have the following requirement where I need to open the ActivitySectionV2 page from a detail schema. More specifically, I've created a button in a custom detail which, when pressed, opens the ActivitySectionV2 page, as you can see in the following image.

 

In addition to opening the page, this button should transfer the records Contact Id from the detail  to the Activity section. Inside the ActivitySectionV2 page, I'll use these values for the QuickFilters of the Employees.

 

 

To achieve this, I tried using messages between modules. And also, loading the section module through the detail but both didn't work. 

 

Detail Schema

messages: {
			"SetActivityFilters": { 
				mode: Terrasoft.MessageMode.BROADCAST,
				direction: Terrasoft.MessageDirectionType.PUBLISH
			}
},
methods: {
openActivities: function(){
 
				var collection = this.get("Collection");
 
				var contactIds = [];
 
				for(var i = 0; i < collection.collection.items.length; i++){
					if(collection.collection.items[i].values.imdContact !== undefined){
						contactIds.push(collection.collection.items[i].values.imdContact.value);
					}
				}
 
				window.console.log(contactIds);
 
 
 
				//Open Activity + Send Contacts
				this.sandbox.publish("SetActivityFilters", contactIds, [this.sandbox.id]);
				this.sandbox.publish("PushHistoryState", {hash: "SectionModuleV2/ActivitySectionV2"});
 
 
				/*this.sandbox.loadModule("SectionModuleV2", {
					renderTo: "centerPanel",
					//id: "SectionModuleV2_ActivitySectionV2",
					instanceConfig: {
						parameters: {
							ContactIds: contactIds 
						},
						schemaName: "ActivitySectionV2",
						isSchemaConfigInitialized: true,
						useHistoryState: true,
						//isSeparateMode: true,
						//entitySchemaName: "Activity",
				  }
		  });*/
}}

 

ActivitySectionV2

 

			messages: {
			         "SetActivityFilters": { 
				          mode: Terrasoft.MessageMode.PTP,
				          direction: Terrasoft.MessageDirectionType.SUBSCRIBE
			         }
		    },		
            methods: {
             init: function(){
				this.callParent(arguments);
				this.sandbox.registerMessages(this.messages);
				this.processMessages();
 
				//window.console.log(this.parameters);
			},
 
			onRender: function(){
				this.callParent(arguments);
			},
 
			processMessages: function() {
				this.sandbox.subscribe("SetActivityFilters", function(result){
 
					window.console.log("'MessageToSubscribe' received" + result);
 
				}, this, ["SectionModuleV2_CaseSection_CardModuleV2_detail_imdSchema54bae29aDetail1d5019a5imdCaseParticipants"]);
			}}

Could you please tell me if there is any other way I can achieve this requirement and what is wrong with my approach.

 

Thanks in Advance.

 

Best Regards,

Pedro Pinheiro

Like 1

Like

3 comments

Hello Pedro,

 

Current code you shared will open the Activity section indeed, but there is no logic in the code that will add values to the quick owner filter. And it's so since it's impossible to do via the scenario you described. Why: because to set such filtration dynamically the addNonPeriodFilterValue method from the FixedFilterViewModelV2 should be called (just check it in the debugger when selecting owner from the lookup inside the filter) and I found no ways of doing that from the init method of ActivitySectionV2. So you need to find other ways of achieving the business task.

Hi Oleg Drobina,

 

Thanks for the response.

 

Currently, to simplify the problem. I'm just trying to fully open the ActivitySection and print the values that are coming from the detail, without applying the filters.

 

To do this I had to change the initial code, because my activity was not receiving the "SetActivityFilters" message. So, what I did was to load the module instead, using the following code:

methods: {
			onActiveRowAction: function(buttonTag, primaryColumnValue) {
				this.mixins.ConfigurationGridUtilitiesV2.onActiveRowAction.call(this, buttonTag, primaryColumnValue);
			},
 
			init: function(){
				this.callParent(arguments);
			},
 
			openActivities: function(){
 
				var collection = this.get("Collection");
 
				var contactIds = [];
 
				for(var i = 0; i &lt; collection.collection.items.length; i++){
					if(collection.collection.items[i].values.imdContact !== undefined){
						contactIds.push(collection.collection.items[i].values.imdContact.value);
					}
				}
 
				window.console.log(contactIds);
 
				this.sandbox.loadModule("SectionModuleV2", {
					renderTo: "centerPanel",
					id: "SectionModuleV2_ActivitySectionV2",
					instanceConfig: {
						parameters: {
							ContactIds: contactIds 
						},
						schemaName: "ActivitySectionV2",
						isSchemaConfigInitialized: true,
						useHistoryState: false,
					}
				});
			}
}

I followed this post in the community to try to implement this https://community.creatio.com/questions/pass-parameters-section

 

When pressing the "Open Activity" button, I get this error and behaviour:

 

After some debbuging, I found that the context does not have the module that I'm trying to load. Maybe, I'm missing some dependencies.

 

 

Could you please help me understand this issue?

 

Once I figure this out, I will check another approach to apply the filters.

 

Thank you.

 

Best Regards,

Pedro Pinheiro

 

 

 

 

 

 

 

 

To pass values from the detail (in my example it was ContractDetailV2) to the ActivitySectionV2:

 

1) In the ContractDetailV2:

onOpenActivityButtonClick: function() {
				this.sandbox.publish("PushHistoryState", {
					hash: "SectionModuleV2/ActivitySectionV2",
					silent: false,
					stateObj: {
						value: "5266908c-f3d1-4c5c-9097-f0dfbdbf900b",
						displayValue: "Email Supervisor"
					}
				});
			}

Here you can pass an array in the "value" property of the stateObj object as well.

 

onOpenActivityButtonClick is a click-handler for the button:

{
                "operation": "insert",
                "name": "OpenActivityButton",
                "parentName": "Detail",
                "propertyName": "tools",
                "values": {
                    "itemType": Terrasoft.ViewItemType.BUTTON,
                    "caption": {"bindTo": "Resources.Strings.OpenActivityButtonCaption"},
                    "click": {"bindTo": "onOpenActivityButtonClick"},
                    "style": Terrasoft.controls.ButtonEnums.style.TRANSPARENT,
                    "enabled": true
                }
            }

 

2) In the ActivitySectionV2:

define("ActivitySectionV2", [], function() {
	return {
		entitySchemaName: "Activity",
		details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
		diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/,
		methods: {
			init: function() {
				this.callParent(arguments);
				var shouldUpdateFilter = this.checkHistoryState();
				if (shouldUpdateFilter.value &amp;&amp; shouldUpdateFilter.displayValue) {
					var tag = "Owner";
					var row = {
						value: shouldUpdateFilter.value,
						displayValue: shouldUpdateFilter.displayValue
					}
					console.log("Row value: " + row.value + " and Row displayValue: " + row.displayValue);
				}
			},
			checkHistoryState: function() {
				var historyState = this.sandbox.publish("GetHistoryState");
				return historyState?.state;
			}
 
		}
	};
});

As a result you will be able to get passed values in the init method execution:

Show all comments