Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Get selected listitem title in SharePoint Hosted App

$
0
0

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


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>