0

I have got two lists one with one site number in record, and one with many site numbers in one column:

-------------------- --------------------------------- | Site | Name | | Surname | SiteConnect | -------------------- --------------------------------- | 3 | Adam | | Jobs | 3; 5; 9 | -------------------- --------------------------------- | 5 | Paul | | Wozniak | 5; 11; 16 |

And if user check 5 it should be Shown on a View two rexords Jobs and Wozniak, because the 5 are in SiteConnect in both record. I Have got this code, how change this code to get in the "Testowa Lista" with SiteConnect all the selected Site in first list:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 
<script>
var abc = function()
{
getSelectedItems().then(function(items){
var myItems = '';
var i;
document.getElementById("p1").innerHTML="";
for (i in items){
    myItems = items[i].get_id();
    site = items[i].get_item("SITE");
    document.getElementById("p1").innerHTML += items[i].get_id() +" "+ site +" "+ items[i].get_item("Title")+" "+ items[i].get_item("kierownik")+" "+ items[i].get_item("konsultant")+"<br />";
    window.location.href = window.location.pathname + window.location.search + window.location.hash;
    var targetListItem;
    updateListItem(myItems, site);
    }
}
    )
}

function updateListItem(j, site) {
    var siteUrl = '/sites/MCUW-IT/kostka-pilotaze/restauracje-pilotaże/';
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Testowa Lista');
    //this.oListItem = oList.getItemById(j);

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Contains><FieldRef Name="SiteConnect"/><Value Type="LookupMulti">site</Value></Contains></Where></Query><RowLimit>1</RowLimit></View>');
    this.collListCoursesItem = oDetailsTempList.getItems(camlQuery);

    clientContext.load(collListCoursesItem, 'Include(Id, SectionID)');

     var listItemEnumerator = listItems.getEnumerator();
    while (listItemEnumerator.moveNext()){
    var oListItem = listItemEnumerator.get_current();
        var title = oListItem.get_item('Title');
console.log(title);


    oListItem.set_item('Poka_x017c_WWidoku', 'Tak');

    oListItem.update();

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    alert('Item updated!');
}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


function getSelectedItems()
{
    var dfd = $.Deferred(function () {
       var context = SP.ClientContext.get_current();
       var listId = SP.ListOperation.Selection.getSelectedList(); //get selected list Id
       var selectedItemIds = SP.ListOperation.Selection.getSelectedItems(context); //get selected objects
       var list = context.get_web().get_lists().getById(listId);
       var listItems = [];
       for (idx in selectedItemIds)
       {
          var item = list.getItemById(parseInt(selectedItemIds[idx].id));
          listItems.push(item);
          context.load(item);
       }
       context.executeQueryAsync(
         function() {
            dfd.resolve(listItems);
         },
         function (sender, args) {
               dfd.reject(args.get_message());
         }
       ); 
    });
    return dfd.promise();   
}
</script>

<input id="123" onclick="abc();" type="button" value="Pokaż rekordy"/>
<div>
   <p id="p1">​​<br/></p>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.