none
How to get image url in Image in List Enhanced text column using query RRS feed

  • Question

  • We need to get url of image stored in Enhanced text column in sharepoint list using jsom 

    Thanks in advance 

    Tuesday, August 13, 2019 4:09 PM

All replies

  • Hi

    First, you need to get current item.

    https://sharepoint.stackexchange.com/questions/101003/get-current-list-item

    Then get the rich field content by

    listItem.get_item("<rich field name>");

    Last, https://stackoverflow.com/questions/33142106/how-to-get-the-src-of-img-tag-using-jquery


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    Wednesday, August 14, 2019 1:19 AM
  • Hi MaghV,

    In Enhanced Text column, the image is store as <img > tag and the url is from the img src attribute, please refer the Jsom code snippet below:

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.js"></script>
    <script type="text/javascript">
    	var clientContext = null;
    	var web = null;
    	ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
    	function Initialize()
    	{
    
    	clientContext = new SP.ClientContext.get_current();
    	web = clientContext.get_web();
    	var list = web.get_lists().getByTitle("currency");
    	var camlQuery = new SP.CamlQuery();
    	var q = "<View><RowLimit>100</RowLimit></View>";
    	camlQuery.set_viewXml(q);
    	this.listItems = list.getItems(camlQuery);
    	clientContext.load(listItems, 'Include(Id, Title, RichText)');
    	clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
    	Function.createDelegate(this, this.onQueryFailed));
    	}
    	function onListItemsLoadSuccess(sender, args) {
    	var listItemEnumerator = this.listItems.getEnumerator();
    	while (listItemEnumerator.moveNext()) {
    	var item = listItemEnumerator.get_current();
    	var itemId = item.get_id();
    	var curBody = item.get_item('RichText');
        console.log(curBody);
        console.log($(curBody).find("img").attr("src"));
        
    	}
    	}
    
    	function onQueryFailed(sender, args) {
    	alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    	}
    </script>

    First line is the Enhanced Text column value generated by multiple html element including <img>,second line is the image url:

    Thanks

    Best Regards


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Wednesday, August 14, 2019 2:56 AM
  • Hi MaghV,

    Is there any updates ?

    Thanks

    Best Regards


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

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, August 22, 2019 1:28 AM