I have set up an async query in javascript. I am able to send a list item and get the column values back. However, is there any way to send the webpart object itself or an entire list object so that I can process multiple items.
Here is what I have that works;
<script type="text/javascript">
function clickMethod_Mailto() {
var ctx = SP.ClientContext.get_current();
var listId = SP.ListOperation.Selection.getSelectedList(ctx); //selected list Id
var items = SP.ListOperation.Selection.getSelectedItems(ctx); //selected Items Ids
var list = ctx.get_web().get_lists().getById(listId);
var i;
mailto ='';
for (i in items)
{
targetListItem = list.getItemById(items[i].id);
ctx.load(targetListItem);
ctx.executeQueryAsync(Function.createDelegate(this, this.OnSuccess), Function.createDelegate(this, this.OnFailure));
}
}
function OnSuccess() {
alert(targetListItem.get_item('Mailto'));
}
function OnFailure() {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>
<input id="clickMe" type="button" value="E-Mail Selected" onclick="clickMethod_Mailto();" />
However, I run into the problem that the async query will run multiple times. I want to put the loop part inside the async call using something like;
ctx.load(ctx);
But this fails.
So what can I pass to an async call? Are there any limits on what can or can't be passed via the .load method.
This is related to a my previous question here but using a different approach to the one I requested help on.
Any help gratefully appreciated.
<input id="clickMe" type="button" value="E-Mail Selected" onclick="clickMethod_Mailto();" />
How do I call the getSelectedItems().then(function(items){..}? – unibod50 May 14 '18 at 13:37executeQueryAsync
. Alternatively, try using REST instead of JSOM. Building the$filter
would be a lot more simple than a CAML query. – wjervis May 14 '18 at 15:00