Tuesday, 30 June 2015

Filter the Lookup feild data based on some condition

We may have some requirement that we do not want to show all data of the lookup to every one.

I have some scenario as below :

I have the Master custom list named OfficeMaster and I use the lookup using this in Child list 'FacilityStatus'.

OfficeMaster Custom also had one more column named OfficeAdmin , which have the office Admin name, who can add data for this office.

In that, I just want to show that Office To admin , which office is assigned to him in the OfficeMaster List.

For that, I used the SPServices named "SPFilterDropdown()".

So, when Office Admin Login into the site, he can only see that offices whom Admin he is.

$().SPServices.SPFilterDropdown({
                                                  relationshipList: "OfficeMaster",
                                                  relationshipListColumn: "OfficeLocation",
                                                  columnName: "OfficeName",                                                                                                
                                                                                             
                                                  CAMLQuery: "<Eq><FieldRef Name='OfficeAdmin' /><Value Type='User'>"+username+"</Value></Eq>",
                                                  completefunc: null,
                                                  debug: true
                                                });
 
 


Here , username parameter is used which uses the users username. I am using the ECMA script for that and put that code above that.

this.context= SP.ClientContext.get_current();
            if (this.context!= undefined && context!= null) {

//assume we have a client context called context.
var web = context.get_web();
var user = web.get_currentUser(); //must load this to access info.
context.load(user);
//alert('start In Middle');
context.executeQueryAsync(function(){
  // alert("User is: " + user.get_title()); //there is also id, email, so this is pretty useful.
   
   username=user.get_title();
}, function(){alert(":(");});
}

No comments:

Post a Comment