0

I need some advice. Because of asynchronous nature of querying SP lists (I use executeQueryAsync) I have no idea if it is possible to do something like that: I'd like to query first list and get some data from different columns, next using this data as a query parameters I'd like to query another lists to build up final table to display on site. Any advice will be helpful. Thanks in advance.

0

the problem of querying async is not being capable of of controlling the moment where you get the data and the script status.

i've tried to implement event listeners to make the async handle like a "sync" function, but it won't always work as expected and is not considered a best practice.

the best approach is to add a function to your success callback

clientContextFirst.executeQueryAsync(Function.createDelegate(this, SuccessFirst), Function.createDelegate(this, Failed)); 

function successFirst()
{

//new spClinetContextsecond after extracting your values 
clientContext.executeQueryAsync(Function.createDelegate(this, SuccessSecond), Function.createDelegate(this, Failed)); 
}
function failed()
{


} 
function successSecond()
{
 extract results

} 

consider making your client context or loaded variables global

  • I used this approach but the problem is that I have to use result from one query as a parameters another. Finally I have to run 3 times executeQueryAsync but you never know the sequence. At this moment I decided to use synchronous method by setting parameter async:false – Marek Lopi Mar 15 '18 at 11:07

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.