The CreatorCon Call for Content is officially open! Get started here.

Attachment widget not uploading file

Community Alums
Not applicable

Hi All,

I have created an attachment widget to use it as a variable in a catalog item. We are able to select the file but the file upload is not happening.Can anyone help me to identoiy the issue?

HTML

<div id="sc_cat_item" >

         

                          </div>

                          <now-attachments-list template="sp_attachment_single_line" ></now-attachments-list>

                         

                          <label style="float:left;font-weight:normal;cursor:pointer;"><sp-attachment-button></sp-attachment-button><span style="padding-left:4px;">${please fill them in excel and attach it to this request.}<br>Click <a>here</a> to add an attachment</span></label>

  <sp-message-dialog name="delete_attachment"

                                            title="{{m.dialogTitle}}"

                                            message="{{m.dialogMessage}}"

                                            ok="{{m.dialogOK}}"

                                            cancel="{{m.dialogCancel}}"

                                            dialog-class="delete-dialog"/>

Client Script

function ($scope, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce) {

  var c = this;

  c.quantity = 1;

  $scope.data.sc_cat_item.description = $sce.trustAsHtml($scope.data.sc_cat_item.description);

  $scope.m = $scope.data.msgs;

  $scope.submitButtonMsg = $scope.m.submitMsg;

  var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});

  ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);

  function setAttachments(attachments, action) {

  $scope.attachments = attachments;

  }

  $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

          }

      })

  }

}

Server Script

// populate the 'data' variable with catalog item, variables, and variable view

(function() {

  var m = data.msgs = {};

  m.submitMsg = gs.getMessage("Submit");

  m.submittedMsg = gs.getMessage("Submitted");

  m.createdMsg = gs.getMessage("Created");

  m.trackMsg = gs.getMessage("track using 'Requests' in the header or");

  m.clickMsg = gs.getMessage("click here to view");

  m.dialogTitle = gs.getMessage("Delete Attachment");

  m.dialogMessage = gs.getMessage("Are you sure?");

  m.dialogOK = gs.getMessage("OK");

  m.dialogCancel = gs.getMessage("Cancel");

  if (input)

  data.sys_id = input.sys_id;

  else

  data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');

  data._attachmentGUID = gs.generateGUID();

  // portal can specify a catalog home page

  data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";

  var validatedItem = new GlideappCatalogItem.get(data.sys_id);

  if (!validatedItem.canView())

  return;

})()

Thanks and Regards,

Kirti

1 ACCEPTED SOLUTION

larstange
Mega Sage

You need to clone the widget to modify it. Below is my best guess - i haven't tested the code, but are using something similar in my end.



Then add this line in the client script



//Send attachment guid variable widgets - wait for the widgets to load


setTimeout(function(){ $rootScope.$broadcast('sp.rp.attachguid', $scope.data._attachmentGUID); }, 1000);



In your own widget add a listener - and initialize the attachment handler in this


//Listen for the attachment GUID


$scope.$on('sp.rp.attachguid', function(e,guid) {


  $scope.data._attachmentGUID = guid;


  var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});


  ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);


  function setAttachments(attachments, action) {


  $scope.attachments = attachments;


  }


  $scope.attachmentHandler.getAttachmentList();


});



Remove the line generating the guide in the server script



data._attachmentGUID = gs.generateGUID();


View solution in original post

16 REPLIES 16

Hi Kirti


Can you please share the working widget code.



Thanks


Hi Lars, I've taken the following code and saved it as a custom widget called "custom-attachments":

find_real_file.png

I have a separate table widget and want to embed custom-attachments into each row:

<td>
  <widget id="custom-attachments"></widget>
</td>

When we press my submit button, we would like new Workforce Admin Cases to be created for each row in the table and if that row has any attachments, we would want those attachments to be attached to their respective cases.  

find_real_file.png

We've tested the widget above and those two test files do appear on the sys_attachment table, but we're having issues getting those to attach to the workforce admin case table.  Can you provide some insights on how to do this since we're not using the catalog item widget?

Community Alums
Not applicable

Sorry for the late response!



Here is the working code.


html



<div id="new_cat_item" style="padding:5px;">


<button onclick="dlTemp();" style="margin:5px;">Download Template</button>



</div>


<script>


function dlTemp() {


window.open(window.location.hostname + '/sys_attachment.do?sys_id=76bc0df06f7672802f29e9e44b3ee4c0');


}


</script>                        








<now-attachments-list template="sp_attachment_single_line" ></now-attachments-list>


                         


    <label style="float:left;font-weight:normal;cursor:pointer;" ng-click="checkSysId()">


        <sp-attachment-button></sp-attachment-button><span style="padding-left:4px;">


        ${Please attach list of servers with planned start date/time and end date/time in csv format}


            </span>


</label>




  <sp-message-dialog name="delete_attachment"


                                            title="{{m.dialogTitle}}"


                                            message="{{m.dialogMessage}}"


                                            ok="{{m.dialogOK}}"


                                            cancel="{{m.dialogCancel}}"


                                            dialog-class="delete-dialog"/>





CLient Controller



function ($scope, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce) {


var c = this;


c.quantity = 1;


$scope.m = $scope.data.msgs;






$scope.$on('sp.rp.attachguid', function(e,guid) {


    $scope.data._attachmentGUID = guid;





    var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});


    ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);


    function setAttachments(attachments, action) {


    $scope.attachments = attachments;


    }


    $scope.attachmentHandler.getAttachmentList();


});



//var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});


  //ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);


  //function setAttachments(attachments, action) {


  //$scope.attachments = attachments;


  //}


  //$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


          }


      })


  }




 





$scope.checkSysId = function()


{


//console.log("test attach", $scope.data.q);


}


}


johan4
Tera Contributor

Hi kirti,

 

This exactly the solution I am looking for. I tried it but I have the problem that the file is not attached to the requested item.

How did you solve it?

 

Many thanks in advance

 

 

Johan, Did you get this figured this out?