how can we show comments count and link to comments in idea portal ?

RushiM
Tera Contributor

I want to show total number of comments on the idea portal for each idea. and also when click on comments then go the comments section.
Just like i want I am attaching the picture.

1 ACCEPTED SOLUTION

Marco0o1
Tera Sage

Hi @RushiM : 

I created the functionality using those steps:

 

Step 1: Go to the Script Include "IMCommonService" and change the "getIdeaInfo" function for this :

IMCommonService.getIdeaInfo = function(ideaGr, isAttachmentsInfoRequired) {
	var _ideaInfo = {};

	var commentNumber = 0; //Return the number of commet
	var comments = new GlideRecord("cf_comment");
	comments.addQuery("source", ideaGr.getValue('sys_id'));
	comments.query();

	while(comments.next()){
		commentNumber ++;
	}


	if(ideaGr.isValidRecord() && ideaGr.canRead()) {
		_ideaInfo = {
			commentNumber: commentNumber, 
			sysId: ideaGr.getValue('sys_id'),
			title: ideaGr.short_description.getDisplayValue(),
			description: ideaGr.idea_description.getDisplayValue(),
			submittedBy: ideaGr.getValue('submitter'),
			submittedByDv: ideaGr.getDisplayValue('submitter'),
			stateDv : ideaGr.getDisplayValue('state'),
			state : ideaGr.getValue('state'),
			score : ideaGr.getValue('score'),
			createdOn: ideaGr.getValue('sys_created_on'),
			updatedOn: ideaGr.getValue('sys_updated_on'),
			isActive: (ideaGr.getValue('active') === "1"),
			ideaTable: ideaGr.getValue('sys_class_name'),
			viewsCount: IMCommonService.getViewCount('im_idea_core', ideaGr.getValue('sys_id'), 'view_count'),
			isIdeaAdmin: gs.hasRole('idea_admin'),
			isIdeaManager: gs.hasRole('idea_manager'),
			isValid: true,
			canDelete: ideaGr.canDelete()
		};
		
		_ideaInfo.canVoteForIdea = ideaGr.getValue('submitter') != gs.getUserID() && _ideaInfo.isActive;
		
		if(!_ideaInfo.isActive) {
			_ideaInfo.closedOn = ideaGr.getValue('closed_at');
			_ideaInfo.closedBy = ideaGr.getValue('closed_by');
			_ideaInfo.closedNotes = ideaGr.getDisplayValue('close_notes');
			_ideaInfo.closedByInfo = IMCommonService.getUserInfoFromId(_ideaInfo.closedBy);
		}
		if(isAttachmentsInfoRequired)
			_ideaInfo.attachmentsData = IMCommonService.getAttachmentsForIdea(_ideaInfo.sysId, _ideaInfo.ideaTable);
		
		if(ideaGr.getValue('state') == '8' && ideaGr.getValue('duplicate')) {
			_ideaInfo.isDuplicate = true;
			_ideaInfo.duplicateIdea = {
				sysId: ideaGr.getValue('duplicate'),
				title: ideaGr.duplicate.getRefRecord().getDisplayValue('short_description')
			};
		}
			
	}
	return _ideaInfo;
};

 

Step 2: Go to the "IM Ideas" 'im_ideas_list' Widget and add that Part between the Created and state item:

                  <span class="idea-separator-dot h3" aria-hidden="true">&#183;</span>
                  <span>
                    {{::idea.commentNumber}} Comments     
                  </span>

 

Then you can test, the part of to link to the comment section you can create that part or just link to the same record using : 

<a class="idea-heading --primary"
                 im-highlight-text="{{data.searchTerm}}"
                 ng-href="?id=view_idea&sysparm_idea_id={{::idea.sysId}}&sysparm_idea_table={{::data.ideaTable}}&sysparm_module_id={{::data.moduleId}}"
                 role="link">
                 {{::idea.commentNumber}} Comments  
              </a>

 

The functionality work for me, i will pass the update  set:

 

Marco0o1_0-1699037814793.pngMarco0o1_1-1699037858191.pngMarco0o1_2-1699037899284.png

 

Hope That Help you.

View solution in original post

2 REPLIES 2

Marco0o1
Tera Sage

Hi @RushiM : 

I created the functionality using those steps:

 

Step 1: Go to the Script Include "IMCommonService" and change the "getIdeaInfo" function for this :

IMCommonService.getIdeaInfo = function(ideaGr, isAttachmentsInfoRequired) {
	var _ideaInfo = {};

	var commentNumber = 0; //Return the number of commet
	var comments = new GlideRecord("cf_comment");
	comments.addQuery("source", ideaGr.getValue('sys_id'));
	comments.query();

	while(comments.next()){
		commentNumber ++;
	}


	if(ideaGr.isValidRecord() && ideaGr.canRead()) {
		_ideaInfo = {
			commentNumber: commentNumber, 
			sysId: ideaGr.getValue('sys_id'),
			title: ideaGr.short_description.getDisplayValue(),
			description: ideaGr.idea_description.getDisplayValue(),
			submittedBy: ideaGr.getValue('submitter'),
			submittedByDv: ideaGr.getDisplayValue('submitter'),
			stateDv : ideaGr.getDisplayValue('state'),
			state : ideaGr.getValue('state'),
			score : ideaGr.getValue('score'),
			createdOn: ideaGr.getValue('sys_created_on'),
			updatedOn: ideaGr.getValue('sys_updated_on'),
			isActive: (ideaGr.getValue('active') === "1"),
			ideaTable: ideaGr.getValue('sys_class_name'),
			viewsCount: IMCommonService.getViewCount('im_idea_core', ideaGr.getValue('sys_id'), 'view_count'),
			isIdeaAdmin: gs.hasRole('idea_admin'),
			isIdeaManager: gs.hasRole('idea_manager'),
			isValid: true,
			canDelete: ideaGr.canDelete()
		};
		
		_ideaInfo.canVoteForIdea = ideaGr.getValue('submitter') != gs.getUserID() && _ideaInfo.isActive;
		
		if(!_ideaInfo.isActive) {
			_ideaInfo.closedOn = ideaGr.getValue('closed_at');
			_ideaInfo.closedBy = ideaGr.getValue('closed_by');
			_ideaInfo.closedNotes = ideaGr.getDisplayValue('close_notes');
			_ideaInfo.closedByInfo = IMCommonService.getUserInfoFromId(_ideaInfo.closedBy);
		}
		if(isAttachmentsInfoRequired)
			_ideaInfo.attachmentsData = IMCommonService.getAttachmentsForIdea(_ideaInfo.sysId, _ideaInfo.ideaTable);
		
		if(ideaGr.getValue('state') == '8' && ideaGr.getValue('duplicate')) {
			_ideaInfo.isDuplicate = true;
			_ideaInfo.duplicateIdea = {
				sysId: ideaGr.getValue('duplicate'),
				title: ideaGr.duplicate.getRefRecord().getDisplayValue('short_description')
			};
		}
			
	}
	return _ideaInfo;
};

 

Step 2: Go to the "IM Ideas" 'im_ideas_list' Widget and add that Part between the Created and state item:

                  <span class="idea-separator-dot h3" aria-hidden="true">&#183;</span>
                  <span>
                    {{::idea.commentNumber}} Comments     
                  </span>

 

Then you can test, the part of to link to the comment section you can create that part or just link to the same record using : 

<a class="idea-heading --primary"
                 im-highlight-text="{{data.searchTerm}}"
                 ng-href="?id=view_idea&sysparm_idea_id={{::idea.sysId}}&sysparm_idea_table={{::data.ideaTable}}&sysparm_module_id={{::data.moduleId}}"
                 role="link">
                 {{::idea.commentNumber}} Comments  
              </a>

 

The functionality work for me, i will pass the update  set:

 

Marco0o1_0-1699037814793.pngMarco0o1_1-1699037858191.pngMarco0o1_2-1699037899284.png

 

Hope That Help you.

RushiM
Tera Contributor

Thank you @Marco0o1, for this solution. It works for me.