0

My column Jurisdiction is a multichoice column. My program is as below :

for (var index = 0; index < ArrayRetrieved.Jurisdiction.results.length; index++)
    $('#jurisdiction option[value="' + ArrayRetrieved.Jurisdiction.results[index] + '"]').prop('selected', true)
    $("#jurisdiction").trigger("chosen:updated");

I get this error : Uncaught TypeError: Cannot read property 'results' of null. how i can resolve this please?

3
  • try it as if(ArrayRetrieved.Jurisdiction){ for (var index = 0; index < ArrayRetrieved.Jurisdiction.results.length; index++) $('#jurisdiction option[value="' + ArrayRetrieved.Jurisdiction.results[index] + '"]').prop('selected', true) $("#jurisdiction").trigger("chosen:updated"); } Commented Sep 18, 2018 at 9:34
  • Yessss thnx! it work :)
    – Jihen
    Commented Sep 18, 2018 at 9:40
  • sharepoint.stackexchange.com/questions/250342/… can you help me?
    – Fabian M
    Commented Oct 9, 2018 at 9:33

1 Answer 1

1

You need to add a null check before the for loop.

Modify your code as below:

if(ArrayRetrieved.Jurisdiction){ 
    for (var index = 0; index < ArrayRetrieved.Jurisdiction.results.length; index++) 
    $('#jurisdiction option[value="' + ArrayRetrieved.Jurisdiction.results[index] + '"]').prop('selected', true) 
    $("#jurisdiction").trigger("chosen:updated"); 
}

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.