1

I'm trying to get the image url for a Hyperlink or Picture column field in a SharePoint list, however after trying a lot of variations I just can't get the url to display in the alert to make sure i'm getting it and my script just stops at that line. Below is my code, any help is greatly appreciated! the field's name is 'Stage' (also the internal name)

function onQuerySucceeded(sender, args) {

var listItemInfo = '';
//set up enumerator to go through list
var listItemEnumerator = collListItem.getEnumerator();
//go through returned list items 
while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() + 
        '\nName: ' + oListItem.get_item('Software_x0020_Name') + 
        '\nStatus: ' + oListItem.get_item('TD_x0020_Status0') +
        '\nStage: ' + oListItem.get_item('Stage').split(',')[0];
2

Make sure you are invoking context.load as below

context.load(collListItem, 'Include(Id,Software_x0020_Name,TD_x0020_Status0,Stage)');

Use onQuerySucceeded as

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    //set up enumerator to go through list
    var listItemEnumerator = collListItem.getEnumerator();
    //go through returned list items 
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo = oListItem.get_item('Stage').get_url();
        alert(listItemInfo);
    }       
}
  • Thank you for your answer Amal. I have gone ahead and modified my context load to specify the columns and added the .get_url() to my picture column item for the code to match what you have specified, but unfortunately the code is still crashing... The query succeeds, but the code stops whenever it get to the line: '\nStage: ' + oListItem.get_item('Stage').get_url(); . Might there be another way to reference the column to get the url? as a side question, would it be possible to 'set' a new url? Thank you for your time. – Anuar J Nov 11 '14 at 14:32
  • @AnuarJ I have updated the code try that. – Amal Hashim Nov 11 '14 at 14:33
  • just edited it, still not getting anything... and again it breaks just at the OlistItem.get_item('Stage').get_url(); line. I tried to alert some message after it but before the alert(listItemInfo) but its clearly not even assigning anything to the listItemInfo variable. I'm just boggled as to why the .get_url() is not working... – Anuar J Nov 11 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.