Adding attachment in service portal User profile

arey yaar
Giga Guru

Need to add attachment in user profile page in service portal.

Where the attachment should be displayed in users profile.

5 REPLIES 5

Akhil Kumar1
Mega Sage

Add the ticket attachment widget to user profile page in your portal.

For example please find below the OOB ticket page with incident form URL.

 

https://yourinstance.service-now.com/sp?id=ticket_akhil&table=incident&sys_id=9d385017c611228701d221...

 

OOB Page id : ticket

OOB Attachment wideget : Ticket Attachments

Hi Akhil,

The below link not opening and showing nelow error

find_real_file.png

 

please suggest.

And as i am new to here, could you please help me with code, so that i can achieve this.

Since 1 week i am trying to achieve this but could not get any proper answer from our community.

Please help.

 

 

Regards,

manmath

 

 

 

Please find the below code which will attach your files in the backend (you can check the sys_attachment table).

 

HTML -

<div>
Select File : <sp-attachment-button></sp-attachment-button>
</div>

 

Client Script - 

function($scope, $http, spScUtil, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n, $timeout, $log, spAriaUtil, $document, spModal) {
  /* widget controller */
  var c = this;
	
	
	$scope.stickyHeaderTop = '0px';
		$scope.$on('dialog.upload_too_large.show', function(e){
		$log.error($scope.m.largeAttachmentMsg);
		spUtil.addErrorMessage($scope.m.largeAttachmentMsg);
	});
	
	$scope.m = $scope.data.msgs;
	var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, appendError);
	function appendError(error) {
		spUtil.addErrorMessage(error.msg + error.fileName);
	}
	ah.setParams($scope.data._attachmentTable, $scope.data.recordID, 1024 * 1024 * $scope.data.maxAttachmentSize);
	function setAttachments(attachments, action) {
		$scope.attachments = attachments;
		if (action === "added")
			{
				console.log("added");
				c.server.update();
			}
			
		if (action === "renamed"){
			console.log("remaned");
			spAriaUtil.sendLiveMessage($scope.m.renameSuccessMsg);
			c.server.update();
		}
		if (action === "deleted"){
			console.log("deleted");
			spAriaUtil.sendLiveMessage($scope.m.deleteSuccessMsg);
			c.server.update();
		}
	}
	$scope.attachmentHandler.getAttachmentList();

	$scope.confirmDeleteAttachment = function(attachment, $event) {
    $rootScope.$broadcast("dialog.delete_attachment.show", {
      parms: {
        ok: function() {
          $scope.attachmentHandler.deleteAttachment(attachment);
          $rootScope.$broadcast("dialog.delete_attachment.close");
        },
        cancel: function() {
          $rootScope.$broadcast("dialog.delete_attachment.close");
        },
        details: attachment.name
      }
    })
  }
	
	$timeout(function() {
        if ($document[0].getElementsByClassName('sc-sticky-item-header').length > 0) {
            var titleHeight = $document[0].getElementsByClassName('sc-sticky-item-header')[0].clientHeight;
            $scope.stickyHeaderTop = '-' + (titleHeight - 20 - $document[0].getElementsByClassName('sc-cat-item-short-description')[0].clientHeight) + 'px;';
        }
    });
	
	$scope.$on('sp_loading_indicator', function(e, value) {
   $scope.loadingIndicator = value;
   });
	
	
	
	
}

 

Server Script - 

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

	data._attachmentTable = "sc_req_item";//here put your table
	data.recordID = "46d91e8bdb800010feeb47823996190d";// this sys_id is of my instance, put your record or req sys_id so that it will be seen in REQ as well
	
	
})();

Hi akhil kumar,

I tried with your code <sp-attachment-button></sp-attachment-button>

it doesnt open any window, to upload a file