tWay to flag a Knowledge article from related search results

gnewuser
Tera Contributor

I am trying to add a "Flag article" button that is opened from the "related search results" in Incident. What is the preferred way to do this.

In the attached images, I would like to add "Flag article" button next to "This helped" button

5 REPLIES 5

Thanks @Sumanth16 for your response.  I have disable suggesting unchecked at the knowledge base level and also at the knowledge article level (which means the users should be able to flag the article). also flagging for the article is possible from the portal and the knowledge home page view. Its just from the contextual search results from incident , the button is not visible. what should I change in the following code to flag artilce is visible in the contextual search result popup from incident?

 

In my flagarticlehandler method I have the following

flagArticleHandler: function () {
		var self = this;
		var overlay = new GlideOverlay({
			id: 'suggestChange',
			title: self.getL10N('Flag this article'),
			width: '60%',
			height: 250,
			fadeInTime: 250,
			onAfterClose: function() {
				$j('#flagArticle').focus();
			},
			draggable: false,
			iframe: 'kb_view_suggest.do?sys_id=-1&sysparm_nostack=yes&sysparm_popup=true',
			onAfterLoad: function () {
				this.setHeight('250px');
				this.autoPosition();
				var doc = overlay.getIFrameElement().contentWindow.document;
				var iframe = $j(overlay.getIFrameElement());
				$j('#suggestChange', iframe.contents()).click({dlg: overlay}, function(eventObj) {
					var comments = doc.getElementById('suggestText').value;
					if (!comments) {
						doc.getElementById('errorMsg').innerHTML = self.getL10N('Please provide a comment');
						doc.getElementById('suggestText').focus();
					} else {
						doc.getElementById("suggestChange").setAttribute("disabled", true);
						var updateAriaLive = function(){
							var elmnt = this.getElementById('messageType');
							elmnt.setAttribute("tabindex","0");
							elmnt.focus();
							this.getElementById('articleText').setAttribute("aria-live", "polite");
						}.bind(document);

						var ajax = new GlideAjax('KBAjax');
						ajax.addParam('sysparm_type', 'kbWriteComment');
						ajax.addParam('sysparm_search', '');
						ajax.addParam('sysparm_id', $j('#articleId').val());
						ajax.addParam('sysparm_flag', true);
						ajax.addParam('sysparm_feedback', escape(comments));
						ajax.addParam('sysparm_isV3', true);
						var kbId = document.getElementById('ts_queryId');
						if(kbId){
							ajax.addParam('ts_queryId', kbId.value);
						}
						ajax.getXMLAnswer(function(answer){
							eventObj.data.dlg.close();
							var data = answer.evalJSON(true);
							if(!data.success)
								return kbViewArticle.showErrorMessage(data.message);
							kbViewArticle.messageBar.show(self.getL10N('Article has been flagged'), 'info');
							updateAriaLive();
						});
					}
				});
				$j('#suggestChangeCancel', iframe.contents()).click({dlg: overlay}, function(eventObj) {
					eventObj.data.dlg.close();
				});
				$j(doc).on('keydown', {
                    dlg: overlay
                }, function(evt) {
                    evt = evt || window.event;
		    // key code for Escape key
                    if (evt.keyCode == 27) {
                        evt.data.dlg.close();
                    }
                });
			}
		});
		overlay.render();
	},

and its being invoked like this

	$j('#flagArticle').click(this.flagArticleHandler.bind(this));