none
How To Pass Data From Script Editor Web Part to Other Web Parts With or Without Using Webpart Connections? RRS feed

  • Question

  • I have this javascript/jQuery code:

    <script type="text/javascript">

    var jq = jQuery.noConflict();


    function getListData(val)
    {
     //this.slctdName = val.toString();
     var serverRelativeUrl=_spPageContextInfo.serverRequestPath;
     var myCntxt = new SP.ClientContext.get_current();
        var oWeb = myCntxt.get_web();
     var list = oWeb.get_lists().getByTitle("Team Member Pictures");
        var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
      
        myCntxt.load(items);
        myCntxt.executeQueryAsync(
         Function.createDelegate(this,function(){captureCorrectPicturePath(items,val);}),
            function(sendera,args)
      {
               console.log(args.get_message());
            }
     );
    }

    function captureCorrectPicturePath(items,val)
    {
     if(val != " ")
     {
      for(var i = 0; i < items.get_count(); i++)
      {
       var item = items.getItemAtIndex(i);   
       var fields = item.get_fieldValues();
       var title = fields.Title.toString();
       var picPath = "";
        
       if(val == title)
       {
        picPath = fields.FileRef;
        jq("#slctdMembrHidn").val(picPath);
        alert("THE 'picPath' VALUE IS (" + picPath.toString() + ").");
        jq("#slctdMembrHidn").val();
       }  
        }
     }
    }

    function processSelectedTeamMember(val)
    {
        getListData(val);

    }

    jq(document).ready(function()
    {
     //alert("DOCUMENT READY! ")
     
        var slctdTmMmbr;

        jq("#slctdTeamMember").on("change", function(event)
        {
      slctdTmMmbr = jq("#slctdTeamMember").val().toString();
        
            if(slctdTmMmbr != " ")
            {
                processSelectedTeamMember(slctdTmMmbr );
            }
        });
     
    });

    </script>

    which works perfectly fine except that it doesn't seem to be updating the path of an image that I've read from an image library into a hidden field, which doesn't seem to be working. So instead of trying to put it into the hidden field how would I pass the path to the image to the image viewer web part's Image Link property. if that can be done?

    Thanks.

    Henry

    Tuesday, March 7, 2017 10:43 PM

All replies

  • Hi Henry,

    You can store the value in a hidden input control like below:

    <input type="hidden" value="" name="testing" />
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    
    <script type="text/javascript">
    $(document).ready(function () { 
        $('input[name="testing"]').val('Work!');
    });
    </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, March 8, 2017 9:22 AM
  • Jerry, Thanks for confirming. I may try to use the JSLink property of the image Viewer webpart (if it has one) to execute a script to handle an onChange event on the hidden field. So when the value of the field changes, to an image path value, then the script would run to dynamically update the webpart's hidden property to false, and update the Image Link property to contain the image path, from the hidden field.

    Does this sound reasonable and doable?

    Let me know when you can.

    Thanks.

    Henry

    Thursday, March 9, 2017 4:56 AM