Hi All,
In a following post we will see how to get Look up Id and
Values from the List using ECMA Script in Apps.
Please find the below Code Snippet.
'use strict';
var SPAppWebUrl;
var spHostUrl;
(function () {
// This code runs when the DOM is ready and creates a
context object which is
// needed to use the
SharePoint object model
$(document).ready(function () {
//getUserName();
spHostUrl =
decodeURIComponent(getQueryStringParameter('SPHostUrl'));
SPAppWebUrl =
decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
$('#btnGetLookup').on('click', function () {
getLookUp();
});
});
function getLookUp() {
var context =
SP.ClientContext.get_current();
if (context !==
undefined && context !== null) {
var parentContext = new
SP.AppContextSite(context, spHostUrl);
var web = parentContext.get_web();
//Name of the child List.
var list = web.get_lists().getByTitle("MyList");
//get the List Item by passing the List
Item ID.
var listItem = list.getItemById(2);
context.load(listItem);
context.executeQueryAsync(ExecuteOnSuccess, ExecuteOnFailure);
}
function
ExecuteOnSuccess() {
var lookup = listItem.get_item("LookupColumnName");
alert("Lookup Id: " + lookup.get_lookupId() + "\n Lookup Value:
" +
lookup.get_lookupValue());
}
function
ExecuteOnFailure(sender, args) {
alert('error' + args.get_message());
}
}
function
getQueryStringParameter(urlParameterKey) {
var params =
document.URL.split('?')[1].split('&');
var strParams = '';
for (var i = 0; i < params.length;
i = i + 1) {
var singleParam = params[i].split('=');
if (singleParam[0] == urlParameterKey)
return
decodeURIComponent(singleParam[1]);
}
}
})();
Thanks.
Related Post
Apps.SharePoint 2013
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint 2013 AppModel Basics
- Something Went wrong error message while deploying App in SharePoint 2013
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Create Folder in document Library using ECMA Script in SharePoint Hosted Apps
- Remove an App from SharePoint Site
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- XMLHttpRequest: Network Error 0x2eff, Could not complete the operation due to error 00002eff.
- Create SharePoint Hosted App in SharePoint 2013
- 101 New Features of Share Point 2013
- Creating Apps in SharePoint 2013
ECMA Script
- Get List Field Type using ECMA Script in SP Hosted Apps
- Get Choice Field Type Values using ECMA Script
- Executing Search Queries using ECMA Script in SharePoint 2013
- Create Site Column and Adding it to Content Type using ECMA Script
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Create Folder in document Library using ECMA Script in SharePoint Hosted Apps
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- How to get List Items Count from SP List Using Visual webpart and ECMA script in SharePoint 2010
- How to get the List Items Count of SP List using ECMA Script in SharePoint 2010 ,2013
- SharePoint Client Object Model using ECMAScript in 2013
0 comments:
Post a Comment