Show Attachments in popup

1231
2
02-20-2017 06:45 AM
RadhikaDirisala
New Contributor

We are trying to bring an attachments in our info-window (POPUP) on service points in our dashboard. I am able to get the attachments in info-window when I am trying to debug with breakpoints and forcefully give the meter number that has attachments then GetAttachments method's return but without debugging code return simple at Queryids method itself  can any one  please help us where is the problem actually . I also tired the classback also but it didn’t work either.

 

Please let me know if you want to know more info we can setup an gotomeeting and look into this.

 

Here is the code

 

if (graphic._layer.name == "SDE.Service") {
            var imageInfos = GetAttachments(meternumber,attributes, serviceType);              
            if(imageInfos != null)
            {
               if(imageInfos.length > 0)
               {
                msg += imageInfos;    
                }
                else
                {
                  msg += "<b> This feature has no associated attachments. </b>";
                }
            }
             else
             {
                    msg += "<b> This feature has no associated attachments. </b>";
             }  
             
                 
            }
            return  msg;
          }

         function GetAttachments(meternumber,attributes, serviceType){  
          var nodes = null;  
          var meterUrl = smartMeterMapURL +"/" +serviceType+"/" +"?token=" + token;
          var featureLayer = new FeatureLayer (meterUrl);
          var query = new esri.tasks.Query();         
          query.where = "METERNUMBER = " + meternumber;
          featureLayer.queryIds(query, function(objectIds){nodes = ImageQuery(objectIds, serviceType);});          
          return nodes;
          }

          function ImageQuery(objectIDs, serviceType){  
          var imageTags = [];
          if(objectIDs != null)
          {    
          var objectID =   objectIDs[0];      
           var attachUrl = smartMeterMapURL + serviceType +"/" + objectID + "/attachments?f=json&token=" + token;
          var attachmentsArray = esriRequest({
                    url: attachUrl,
                         handleAs: "json"
                    });
                    attachmentsArray.then(
          function(response) {
          for(var i = 0; i< response.attachmentInfos.length; i++){
            var ImageNo = response.attachmentInfos.id;
            var imageTag = "<br /><a target='_blank' href=" + smartMeterMapURL + serviceType + "/"+ objectID + "/attachments/"+ ImageNo + "?token=" + token +  "> Attach Image: " + ImageNo +"</a>";
            imageTags.push(imageTag);
            }
           }, function(error) {
           console.log("Error: ", error.message);
            });
            return imageTags;
            }
            else
            {              
              return imageTags;
            }
          }

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Radhika,

   If you have a reference to your FeatureLayer than you should just use:

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.19 | queryAttachmentInfos 

Here is some code I use:

        var ofl = new FeatureLayer(My Feature URL);
        ofl.queryAttachmentInfos(OID, lang.hitch(this, function(info){
          if(info.length > 0){
            var domAttSec = dojoQuery(".attachmentsSection", map.infoWindow.domNode)[0];
            var aWidget = dijit.getEnclosingWidget(domAttSec);
            array.map(info, lang.hitch(this, function(att){
              var attLi = domConstruct.toDom('<li><a href="' + att.url + '" target="_blank">' + att.name +'</a></li>');
              domConstruct.place(attLi, aWidget._attachmentsList);
            }));
            domClass.remove(domAttSec,'hidden');
            aWidget = null;
          }
        }));
        ofl = null;
0 Kudos
RadhikaDirisala
New Contributor

Thank you very much Robert, let me try and update you soon. 

Thanks

Radhika

0 Kudos