Friday 2 March 2018

Get Related item id and list id in sharepoint task list

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getMyTasks);
function getMyTasks() {
var url = window.location.href;
var splitid = url.split("?")[1];// getting id from the url
    splitid = splitid.split("&")[0];
var id = splitid.split("=")[1];
var clientContext = new SP.ClientContext.get_current();   
rptMyTasksList = clientContext.get_web().get_lists().getByTitle('Task List');
//var camlQuery = SP.CamlQuery.createAllItemsQuery();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>"+id+"</Value></Eq></Where></Query></View>");
var rptMyTasksListItems = rptMyTasksList.getItems(camlQuery);
clientContext.load(rptMyTasksListItems);
clientContext.executeQueryAsync(

    function () {
        // Success returned from executeQueryAsync

        if (rptMyTasksListItems.get_count() > 0) {
            var rptMyTasksListItemEnumerator1 = rptMyTasksListItems.getEnumerator();

            // Lets get the select items
            while (rptMyTasksListItemEnumerator1.moveNext()) {
                var rptMyTasksListItem1 = rptMyTasksListItemEnumerator1.get_current();
                var obj = JSON.parse(rptMyTasksListItem1.get_item("RelatedItems"));
                var RelatedItemID = obj[0].ItemId;
            }
        }
        else {

        }

    },
    function (sender, args) {
        // Failure returned from executeQueryAsync
        alert("Error in XXXXXX Tasks: " + args.get_message());
    }
    );

}

No comments:

Post a Comment

Featured post

Data connections in Infopath forms

https://www.qdoscc.com/blog/how-automatically-retrieve-current-username-infopath-sharepoint-list-form

Popular Posts