Enable View Mode - Based on Conditions

Hi Team,

We have a business use-case like enabling the MiniPage (View Mode) in the activity section based on conditions. I have enabled the view mode of the MiniPage, now I am able to see the mini page for all the records. But I need to show it for the records based on some conditions like (Eg: Title = "Appointment").



How to achieve this kind of implementation?



Regards,

Adharsh S

Like 0

Like

5 comments
Best reply

Hi Adharsh,

 

The logic below will make a mini page in view mode not appear on the page in case the title of the activity contains the "Visit" word.

 

Create a replacing view model for the ActivitySectionV2 and add the following code there:

define("ActivitySectionV2", [],
	function() {
		return {
			entitySchemaName: "Activity",
			attributes: {
				"ResultGridSet": {
					"dataValueType": this.Terrasoft.DataValueType.TEXT,
					"type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
					"value": ""
				}
			},
			mixins: {},
			methods: {
				onGridDataLoaded: function(response){
					this.callParent(arguments);
					var subjectsToExclude = "";
					Terrasoft.each(response.collection.getItems(),function(item){
						var activityTitle = item.values.Title;
						var activityId = item.values.Id;
						if (activityTitle.indexOf("Visit")!= -1){
							subjectsToExclude = subjectsToExclude + activityId +",";
						}
					});
					subjectsToExclude = subjectsToExclude.substring(0, subjectsToExclude.length - 1);
					this.set("ResultGridSet", subjectsToExclude);
				},
				prepareMiniPageOpenParameters: function(options, entityInfo){
					var rowId = options.rowId;
					var gridSet = this.get("ResultGridSet");
					if (gridSet.indexOf(rowId)!=-1){
						return;
					}
					this.callParent(arguments);
				}
			},
			diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
		};
	}
);

The logic is simple:

 

1) onGridDataLoaded method is always called when the grid is loaded in the section. It contains the response argument which contains actual data that is stored in the grid (and we can use it).

 

2) Once onGridDataLoaded is called we take the response and check if the activity title contains the "Visit" word and perform this check for each item in the grid. If the activity title contains the "Visit" word we take an Id value for this activity and add it to the string subjectsToExclude parameter.

 

3) subjectsToExclude parameter result will be then passed to the ResultGridSet attribute that will be then used inside the prepareMiniPageOpenParameters method.

 

4) prepareMiniPageOpenParameters method is the method from base MiniPageUtilities mixin and we need to override its logic in the Activities section. prepareMiniPageOpenParameters has the options argument that is primary data regarding the activity on which the mouseover event was called. We can get the activity id from the options argument and use it further.

 

5) Inside the prepareMiniPageOpenParameters method we get the ResultGridSet attribute value and then check if the Id that was received from options can be found inside the ResultGridSet string. If it can be found the prepareMiniPageOpenParameters does nothing (and as a result the minipage is not opened), else - perform the parent method execution.

 

Feel free to create your own logic based on this example.

 

Best regards,

Oscar

Hi Adharsh,

 

The logic below will make a mini page in view mode not appear on the page in case the title of the activity contains the "Visit" word.

 

Create a replacing view model for the ActivitySectionV2 and add the following code there:

define("ActivitySectionV2", [],
	function() {
		return {
			entitySchemaName: "Activity",
			attributes: {
				"ResultGridSet": {
					"dataValueType": this.Terrasoft.DataValueType.TEXT,
					"type": this.Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
					"value": ""
				}
			},
			mixins: {},
			methods: {
				onGridDataLoaded: function(response){
					this.callParent(arguments);
					var subjectsToExclude = "";
					Terrasoft.each(response.collection.getItems(),function(item){
						var activityTitle = item.values.Title;
						var activityId = item.values.Id;
						if (activityTitle.indexOf("Visit")!= -1){
							subjectsToExclude = subjectsToExclude + activityId +",";
						}
					});
					subjectsToExclude = subjectsToExclude.substring(0, subjectsToExclude.length - 1);
					this.set("ResultGridSet", subjectsToExclude);
				},
				prepareMiniPageOpenParameters: function(options, entityInfo){
					var rowId = options.rowId;
					var gridSet = this.get("ResultGridSet");
					if (gridSet.indexOf(rowId)!=-1){
						return;
					}
					this.callParent(arguments);
				}
			},
			diff: /**SCHEMA_DIFF*/[]/**SCHEMA_DIFF*/
		};
	}
);

The logic is simple:

 

1) onGridDataLoaded method is always called when the grid is loaded in the section. It contains the response argument which contains actual data that is stored in the grid (and we can use it).

 

2) Once onGridDataLoaded is called we take the response and check if the activity title contains the "Visit" word and perform this check for each item in the grid. If the activity title contains the "Visit" word we take an Id value for this activity and add it to the string subjectsToExclude parameter.

 

3) subjectsToExclude parameter result will be then passed to the ResultGridSet attribute that will be then used inside the prepareMiniPageOpenParameters method.

 

4) prepareMiniPageOpenParameters method is the method from base MiniPageUtilities mixin and we need to override its logic in the Activities section. prepareMiniPageOpenParameters has the options argument that is primary data regarding the activity on which the mouseover event was called. We can get the activity id from the options argument and use it further.

 

5) Inside the prepareMiniPageOpenParameters method we get the ResultGridSet attribute value and then check if the Id that was received from options can be found inside the ResultGridSet string. If it can be found the prepareMiniPageOpenParameters does nothing (and as a result the minipage is not opened), else - perform the parent method execution.

 

Feel free to create your own logic based on this example.

 

Best regards,

Oscar

Oscar Dylan,

Thanks for the reply.



One small change in the code,

Instead of , var rowId = options.rowId;

You can choose  var rowId = entityInfo.recordId;



Because, options.rowId returns "undefined".



Regards,

Adharsh S

Adharsh,

 

You are welcome.

 

This is strange, in my code options.rowId returned values and entityInfo was always undefined:

Maybe it behaves differently in different sections... Anyway, debugging will always provide a correct way to get the data needed:)

 

Best regards,

Oscar

Oscar Dylan,

 

It is interesting. Might be it behaves differently in different sections. But I see your screenshot, you have debugged in the ActivitySection right. I have implemented the functionality on the same schema page. It seems to be weird behaving different across instances!



Regards,

Adharsh S

Oleg Drobina,



Could you please share how did you debug the client code using IDE.

Creatio doesn't have an article for the de-bugging the JS files in realtime using IDE. If you could share the steps it would be of great help.



BR,

Bhoobalan Palanivelu.

Show all comments