I have a problem with my global variable. I saw that there is fundamental diffenrce the C language's Family.
I would like to reach and modify my variable "number" everywhere. I try with arguments or Returns but as I am not very experienced in JavaScript I failed.
Here is my code
var number;
var message;
$(function () {
ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
});
function runCode() {
// Specify a client context using the server-relative URL of the sub web, load the sub web, and call the ExecuteQueryAsync method.
var clientContext = new SP.ClientContext.get_current();
targetWeb = clientContext.get_web();
clientContext.load(targetWeb);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded1), Function.createDelegate(this, this.onQueryFailed1));
}
function onQuerySucceeded1() {
// On success, use get_ property assessor methods to return the value of the Title, ID, Language, uiVersion, Description, and Created properties of the SP.Web object.
number = targetWeb.get_title();
message = "<strong>Meldung: </strong>" + targetWeb.get_title();
}
function onQueryFailed1(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Auftragsordner');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Title\'/>' +
'<Value Type=\'Text\'>'+number+'</Value></Eq></Where></Query></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(this.collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
initially. – Nadeem Yousuf-AIS May 29 '18 at 8:28