1

I've a lookup additional column and alerting its value in Javascript as:

var oPicture = oListItem.get_item("Image_x003A_People").get_lookupValue()

If I dont add any data in the column it errors, how can this be tested to prevent the error.

Thanks

1 Answer 1

2

Use an IF condition to check whether lookup field contains value or not. Example:

if (oListItem.get_item('Image_x003A_People')) {
    alert(oListItem.get_item('Image_x003A_People').get_lookupValue());
}   
3
  • Did you use a SharePoint tool to work this out? Commented Feb 4, 2015 at 10:50
  • @OrangeJuice, this is a simple JavaScript technique. I did however, test it and it worked perfectly. Commented Feb 4, 2015 at 10:59
  • @OrangeJuice this works because oListItem.get_item('Image_x003A_People') will return null if no value has been assigned -- in JavaScript, null is considered a "falsey" value and will evaluate to false when evaluated inside of a conditional statement... you can read more about this on SO at stackoverflow.com/questions/19839952/…
    – John-M
    Commented Feb 4, 2015 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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