Domanda

Sono molto nuovo a SharePoint e avere la seguente query sui miei documenti condivisi.Sta tornando NULL per tutti e tre i documenti che ho.

Mi sto chiedendo dove controllare il database per vedere se i valori sono nullo o come eseguire il debug in modo sostanzialmente.Posso vedere dove si rompe in VS ma non mi dà alcun indizio da dove provengono null.

Codice:

//ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
var context = null;
var web = null;
var currentUser = null;
var collListItems = null;
var username = null;
var loginname = null;
var isgettinglist = false;
function DisplayUser() {
    isgettinglist = false;
    GetUserData();
}
function DisplayList() {
    isgettinglist = true;
    GetUserData();
}
function GetUserData() {
    //## Getting the context
    context = new SP.ClientContext.get_current();
    //## Getting the web
    web = context.get_web();
    //## Getting the current user
    currentUser = web.get_currentUser();
    //## Load the query
    currentUser.retrieve();
    context.load(web);
    //## Execute the query Async
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
    Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
    //## Setting the object to get the current user...again...
    var userObject = web.get_currentUser();
    //## Adding the user into a Variable
    username = userObject.get_title();
    loginname = userObject.get_loginName();
    if (isgettinglist == false) {
        alert('User name:' + username + '\n Login Name:' + loginname);
    }
    if (isgettinglist == true) {
        //## Getting the results from the list
        GetListByName();
    }
}
function onFailureMethod(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
function SayHello() {
    alert('Hello Word');
}

function GetListByName() {

    //## Get the context again
    context = new SP.ClientContext.get_current();
    //## Get the list
    var list = context.get_site().get_rootWeb().get_lists().getByTitle('Shared Documents');
    //## Builds a CAMEL querty to return items
    var query = new SP.CamlQuery();
    query.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Author"/><Value Type="User">' + username + '</Value></Eq></Where></Query><ViewFields><FieldRef Name="Title"/><FieldRef Name="FileLeafRef"/></ViewFields></View>');
    //## Geting the items
    this.collListItems = list.getItems(query);
    context.load(collListItems);
    //## Execute the query Async
    context.executeQueryAsync(Function.createDelegate(this, this.mySuccessFunction),                   
    Function.createDelegate(this, this.myFailFunction));
}

function mySuccessFunction() {
    // Do something useful like loop through your returned list items and output them somewhere
    // create an enumerator to loop through the list with 
    var listItemEnumerator = this.collListItems.getEnumerator();
    var strHtml = "RESULTS:";
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        strHtml += oListItem.get_item('Title');
    }
    alert(strHtml);
}
function myFailFunction() { alert('Request fail'); }
.

È stato utile?

Soluzione

Confirm these points before running CAML query,

-> Are you calling GetListByName function after loading SP.js? If not use this statement to call your function after SP.js was loaded.

ExecuteOrDelayUntilScriptLoaded(yourfunction, "SP.js");

-> Are you passing username as full name? For eg: If username is Arun Balaji, you should pass whole name as it is. Here Arun is First name and Balaji is Last name.

Altri suggerimenti

In your example I fail to see where do you collect USERNAME. One option could be (let CAML do the job for you by retrieving Current User )

<Where>
    <Eq>
        <FieldRef Name='Author' />
        <Value Type='Integer'><UserID/></Value>
    </Eq>
</Where>

or

<Where>
    <Eq>
        <FieldRef Name='Author'/>
        <Value Type='Text'>Lastname, Firstname</Value>
    </Eq>
</Where>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top