This can be done with Javascript as show microsoft:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-javascript-library-code-in-sharepoint

is neccessary to load jquery on sharepoint ( all pages)

http://smallcitydesign.com/load-jquery-sharepoint-2013/

Steps, on the page, insert a new webpart ( secuence command)

and paste this:

<script   type=”text/javascript”  src=”/_layouts/15/sp.runtime.js”></script>

<script   type=”text/javascript”  src=”/_layouts/15/sp.js”></script>

<script type=”text/javascript” src=”http://mysite.sharepoint.com/Subsite/js/JSRefresh.js”></script>

this, loads the sharepoint objects  to work with javascript, then the code of the js:

$(document).ready(function() {
$(“#ctl00_ctl27_g_9ae14201_a75b_4eb9_b7db_8d49b2e2b27c_ctl00_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00__Lookup”).change(function(){
retrieveProduct(‘/Sistema’,’Productos’,this.value);

});

On the document.ready, simpy add a change function to the element that will be the filter of the second list

function retrieveProduct(siteUrl,list,item) {
var clientContext =new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(list);

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
‘<View><Query><Where><Eq><FieldRef Name=\’ID\’/>’ +
‘<Value Type=\’Number\’>’ + item + ‘</Value></Eq></Where></Query>’ +
‘<RowLimit>10</RowLimit></View>’
);
this.collListItem = oList.getItems(camlQuery);

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

the function RetrieveProduct is executed asyncronously, this function get the description of the product filter by the id of the other field

function onQuerySucceeded(sender, args) {
var listItemInfo = ”;
var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += ‘\nID: ‘ + oListItem.get_id() +
‘\nTitle: ‘ + oListItem.get_item(‘Title’);
retrieveLots(‘/Sistema’,’Lotes’,oListItem.get_item(‘Title’));

}

//alert(listItemInfo.toString());
}

If the function succeded call the other function retrieveLots with the paramenter of the description of the product

function onQueryFailed(sender, args) {
alert(‘Request failed. ‘ + args.get_message() +
‘\n’ + args.get_stackTrace());
}

function retrieveLots(siteUrl,list,item) {
var clientContext =new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(list);

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
‘<View><Query><Where><Eq><FieldRef Name=\’Producto\’/>’ +
‘<Value Type=\’Text\’>’ + item + ‘</Value></Eq></Where></Query>’ +
‘<RowLimit>10000</RowLimit></View>’
);
this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, ProducteTrobat), Function.createDelegate(this, ProducteNoTrobat));
}

The function retrieveLots, get the list Lotes, with one filter “calmQuery” only the lots of the product description filtered.

function ProducteTrobat(sender, args) {
var listItemInfo = ”;
var listItemEnumerator = collListItem.getEnumerator();
var subCategory = $(“select[title=’Lote’]”);
subCategory.find(‘option’).remove().end(); // To clear previous items

while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var o = new Option(oListItem.get_item(‘Lote’),oListItem.get_item(‘Lote’));
/// jquerify the DOM object ‘o’ so we can use the html method
$(o).html(oListItem.get_item(‘Lote’));
subCategory.append(o);
}

var o = new Option(‘0’,”);
/// jquerify the DOM object ‘o’ so we can use the html method
$(o).html(”);
subCategory.append(o);
subCategory.val(0);

//alert(listItemInfo.toString());
}
if we find the produc then, we load the choices of Lots by name , delete all the elements, and add one by one

function ProducteNoTrobat(sender, args) {
alert(‘Request failed. ‘ + args.get_message() +
‘\n’ + args.get_stackTrace());
}

});

Facebooktwitterredditpinterestlinkedinmail