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?

  • 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"); } – Gautam Sheth Sep 18 '18 at 9:34
  • Yessss thnx! it work :) – Jihen Sep 18 '18 at 9:40
  • sharepoint.stackexchange.com/questions/250342/… can you help me? – Fabian M Oct 9 '18 at 9:33
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, privacy policy and cookie policy

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