Hi,
I try to make a SharePoint hosted app that get a listitem and do something with it.
On ‘googling’ I found that I need to use cross-domain script. The security is set on the hostweb (manifest.app)
I can load the web and list context. Only I cannot get the selected listitem and display the title.
In my test case the value of ‘selectedItemID’ = “1”
Client side code is completely new for me. I hope that someone can show me what my mistake is.
When I run this code, I get an alert with the selected document library name (that ‘s OK), but the Title of the item is ‘null’ (NOT OK)
function test()
{
SP.SOD.executeFunc('sp.js','SP.ClientContext', getUrl);
function getUrl() {
var scriptbase = hostweburl +"/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js",
function () { $.getScript(scriptbase +"SP.RequestExecutor.js", execOperation); }
);
}
);
//event.preventDefault();
}
function execOperation() {
context = new SP.ClientContext(appweburl);
var factory =new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostweburl);
web = appContextSite.get_web();
context.load(web);
list = web.get_lists().getById(selectedListID);
context.load(list);
item = list.getItemById(selectedItemID);
context.load(item, "Title");
context.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
alert(list.get_title() + " , " + get_item("Title"));
}
function onFail(sender, args) {
alert(args.get_message());
}
}
Regards,
Johan