0

I have two lists; Cars{brand,color,price} and Colors{designation,disponibility}. I made the field color as a lookup field to display colors from colors list. My problem is that i ONLY want just to display colors that have yes in disponibility field. Can anyone help me please? Thank you in advance.

4
  • Are you willing to write scripts to run this? Or do you want to avoid scripting altogether?
    – Brandon C.
    Commented Jun 30, 2014 at 10:24
  • Hello Brandon, i want to avoid scripting if possible.. but it is not a big deal if i use scripts. Commented Jun 30, 2014 at 10:36
  • Actually, I wrote my answer for scripts, but can you use workflows? I don't see SP designer in your tags, so I wasn'T sure when I wrote my answer
    – Brandon C.
    Commented Jun 30, 2014 at 11:21
  • No, i don't use workflows for the moment Commented Jun 30, 2014 at 12:46

1 Answer 1

0

Since you have to reference two lists, your only option that I see is to use a script to handle it (I originally thought you wanted to filter the color column, and not the Cars column. I don't know of an easy work around, besides creating a new field and using workflows to get it done).

Here is a sharepoint script that could possibly get it done. I can't test it out (might have syntax errors), but it should be the basic gist. You should also probably run this script (If you are going to do this) on an empty list that is a copy of, which you will then use to display the items. Note I am using C# notation.

SPSite oSiteCollection = SPContext.Current.Site;
SPList carList = oSiteCollection.AllWebs["mySite"].Lists["Cars"];
SPList colorList = oSiteCollection.AllWebs["mySite"].Lists["Colors"];
SPList newList = oSiteCollection.AllWebs["mySite"].Lists["newList"];

for (int x = newList.Count-1; x >= 0; x--)
{
  newList[x].Delete();
}
oQuery.Query = "<Where><Eq><FieldRef Name='disponibility'/>" +
"<Value Type='Text'>Yes</Value></Eq></Where>";
SPListItemCollection colorListItems = oList.GetItems(oQuery);  //Only have colors with Yes
SPListItemCollection carListItems = carList.Items;
foreach (SPListItem colorItem in colorListItems) {
   foreach (SPListItem carItem in carListItems) {
       If(carItem["Color"] == colorItem["Color"]) {
          SPListItem newListItem = newList.Items.Add();
          newListItem["Brand"] = carItem["Brand"];
          newListItem["Color"] = carItem["Color"];
          newListItem["Price"] = carItem["Price"];
          newListItem.update();
        }
    }
 }

And then ave the script run whenever disponibility changes. This is probably not the best approach, but it gives you ideas for scripting. There is a way to set HTML elements as well, but I didn't look into it as much.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.