How to fix: Save filtered lookup by current user and status in sharepoint online

I filtered a lookup field by current user id and status using "SP.js CSOM SP.ClientContext" and it was successful in filtering the lookup. But trying to save gave an error "Sorry, Something went wrong", with a correlation ID "9b40ec9e-1004-8000-bbff-36490b07f284". Note: if i take off the filtering, it saves just fine.

I tried using other methods of filtering, using CAML queries and JSOM Ajax calls. All filtering were successful but saving didn't work.

  SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

  function sharePointReady(){
     getItemsFromView("Activity Plan", "Approved",
         function(items){
             var field = getField("select", "My Planned Tasks")

              for(var i = 0; i < items.get_count(); i++){
                  var item = items.get_item(i);
                  var node = document.createElement("option");
                  var textnode = document.createTextNode(item.get_item('Deliverable'));
                  node.appendChild(textnode);
                  field.appendChild(node);

               }
           },
           function(sender,args){ 
              console.log(args.get_message())
           }
       );
    }

  function getItemsFromView(listTitle, viewTitle,success,error){
     var ctx = new SP.ClientContext();
     var list = ctx.get_web().get_lists().getByTitle(listTitle);
     var view = list.get_views().getByTitle(viewTitle);
     ctx.load(view,'ViewQuery');
     ctx.executeQueryAsync(
         function() {
             var viewQry = "<View><Query>" + view.get_viewQuery() + "</Query> 
  </View>";
             getItems(listTitle,viewQry,success,error);
          },
          error);
   }

  function getItems(listTitle, queryText,success,error) {
     var ctx = new SP.ClientContext();
     var list = ctx.get_web().get_lists().getByTitle(listTitle);
     var query = new SP.CamlQuery();
     query.set_viewXml(queryText);
     var items = list.getItems(query);
     ctx.load(items);
     ctx.executeQueryAsync(
         function() {
             success(items);
         },
         error
    );
  }

  function getField(fieldType,fieldTitle) {
       var docTags = document.getElementsByTagName(fieldType);
       for (var i=0; i < docTags.length; i++) {
           if (docTags[i].title == fieldTitle) {
               while (docTags[i].firstChild) {
               docTags[i].removeChild(docTags[i].firstChild);
             }
             return docTags[i];
           }
       }
       return false;
  }

i expect it save on the calendar event list but i got the error message "Sorry, something went wrong" and a correlation id "9b40ec9e-1004-8000-bbff-36490b07f284"

Answers:

Answer

you did not put a value for the option. So it is like an Option without an ID and just Text so need to replace this section

  var textnode = document.createTextNode(item.get_item('Deliverable'));
                  node.appendChild(textnode);

with the following

  var textnode = document.createTextNode(item.get_item('Deliverable'));
                  node.value = item.get_item('ID');
                  node.appendChild(textnode);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.