"The identifier for the property or" Identifier "field was not initialized. It was not requested ..." when trying to access the library GUID in SharePoint using JavaScript

I am trying to access the library ID using the client model of the object in SharePoint 2013. But I get an error message like:

The property or field 'Id' has not been initialized. It was not requested or the request was not completed. You may need to explicitly request it.

Below is my code:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var items = SP.ListOperation.Selection.getSelectedItems(context);
var currentLibrary = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList(context));
context.load(currentLibrary, 'id'); // Tried with 'Id' but still throws error
console.log(currentLibrary);
console.log("currentLibrary.get_id = " + currentLibrary.get_id()); // THROWS ERROR!

What am I doing wrong here?

+4
source share
3 answers

Error:

'Id' . ...

, List .

SP.ClientContext.executeQueryAsync

:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var listId =  SP.ListOperation.Selection.getSelectedList(context); 
var list = web.get_lists().getById(listId);
context.load(list, 'Id');  //tell SharePoint to load List Id property
context.executeQueryAsync(  //submit query to the server
  function(){
    console.log("ID:" + list.get_id()); //process result in success callback
  }, 
  function(sender,args){
    console.log(args.get_message());    //handle error in error callback
  }
);
+4

, , , Requestor_DisplayName, Employee_DisplayName, :

oListItem.get_item('Employee_DisplayName');

>

"The property or field 'Id' has not been initialized. It has not been requested…" error

SP.ClientContext.executeQueryAsync...

:

oListItem.get_item('Requestor_DisplayName');

. SP CAML Query Helper Online ( CAML), :

Screenshot

, - !

. SG.

, , , , , SharePoint 32 ...

, , > (IE f12), , .

"The property or field 'Operations_Approver1_Display_Name' has not been initialized. It has not been requested…"

, JSOM, "Operations_Approver1_Display_Name" (, - COBOL, LOL)

oListItem.get_item('Operations_Approver1_Display_Name');

, , , : ", , , ". , , , , SP CAML Query Helper Online (, , , b LOL).

, SharePoint 32 , , . , InternalName "" ( , 33 1 )

enter image description here

0

you are looking for identifiers, then follow these steps: -

var context = SP.ClientContext.get_current();
var web = context.get_web();
var items = SP.ListOperation.Selection.getSelectedItems(context);
for (var i = 0; i < items.length; i++) {
     var id= items[i].id; 
}

Thank:)

-1
source

All Articles