Filter lookup values by employee

Sviatoslav Bulash -

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("setDefaultValues");
var allowedIds = [];
var empID = -1;
$(document).ready(function(){
filterDevelopmentNeeds();
});
function filterDevelopmentNeeds() {
ExecuteOrDelayUntilScriptLoaded(function () {
// Title - internal field name
var empfield = new Igotta.StandartListFormsUtility.SPFieldLookup('Employee');
empID = empfield.getValue();
try{
if(empID > 0){
filterDDL();
empfield.disable();
}
}
catch(err) {
}
}, "sp.js")

}
function filterDDL(){
$().SPServices({
operation: "GetListItems",
async: true,
listName: "Development Needs",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Employee' LookupId='TRUE'/><Value Type='Lookup'>"+empID+"</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
var $zRows = $(xData.responseXML).SPFilterNode("z:row");
if($($zRows).length > 1){
$($zRows).each(function() {
var ID = $(this).attr("ows_ID");
if (ID != undefined){
allowedIds.push(parseInt(ID));
}
});
} else {
var ID = $($zRows).attr("ows_ID");
if (ID != undefined){
allowedIds.push(parseInt(ID));
}
}

ExecuteOrDelayUntilScriptLoaded(function () {
// Title - internal field name
var field = new Igotta.StandartListFormsUtility.SPFieldLookup('DevelopmentNeed');
// show only needed options
field.filterLookup(allowedIds);
}, "sp.js");
}
});
}
function setDefaultValues() {
var vals = new Object();
vals = fillDefaultValues();
// setLookupFromFieldName("Employee", vals["EmplID"]);
// setLookupFromFieldName("Learning Material", vals["LMID"]);
// setLookupFromFieldName("Training Event", vals["TrID"]);
// hideSelectField("Employee");
// hideSelectField("Learning Material");
// hideSelectField("Training Event");
// hideSelectField("Development Need");
// hideElementByInternalFieldName("HRComments");

}
</script>

 

Have more questions? Submit a request

Comments

  • Avatar
    Sviatoslav Bulash

    Use below script for Lanteria HR 4.4.x versions:

    function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function filter(){
    $().ready(function(){
    var allowedIds = [];
    var emplID = getParameterByName('EmplID');
    var call = $.ajax({
    url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/GetByTitle('Dependents')/items?$select=ID&$filter=Employee/ID eq '"+emplID+"'",
    type: "GET",
    dataType: "json",
    headers: {
    Accept: "application/json;odata=verbose"
    },
    success: function(data){
    $.each(data.d.results, function(index, item){
    var id = item.ID
    allowedIds.push(parseInt(id));
    });
    var field = new Igotta.StandartListFormsUtility.SPFieldLookupMulti('Dependents');
    field.filterLookupMulti(allowedIds);
    }
    });
    });
    }

    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', filter);

Powered by Zendesk