Check list for data in PM

emperorjones

Новичок
Регистрация
18.09.2014
Сообщения
27
Благодарностей
1
Баллы
3
Is it possible in PM to have ZP load a list, check each line for data against a variable and report back whether or not the data exists?

Thanks.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 772
Благодарностей
1 185
Баллы
113
Sure the best and fastest way is to use C#
http://zennolab.com/discussion/threads/search-in-list-and-tables-via-c-macro.10733/

C#:
// take search text from variable
var textContains = project.Variables["listSearchTextContains"].Value;
// get a list or search
var sourceList = project.Lists["SourceList"];
// search in each line of list
lock(SyncObjects.ListSyncer)
{
    for(int i=0; i < sourceList.Count; i++)
    {
        // get line from list
        var str = sourceList[i];
        // check if line contains text, if there are matches return "yes"
        if (str.Contains(textContains))
            return "yes";
    }
}
// ifnothing found return "no"
return "no";
 
  • Спасибо
Реакции: CSS

emperorjones

Новичок
Регистрация
18.09.2014
Сообщения
27
Благодарностей
1
Баллы
3
Thanks!!, i guess now I finally have to learn how to use C# o_O
 

emperorjones

Новичок
Регистрация
18.09.2014
Сообщения
27
Благодарностей
1
Баллы
3
So if my variable is "City" and my list is "MasterCityList"

Does it look like this?

// take search text from variable
var textContains = city.Value;
// get a list or search
var sourceList = MasterCityList;
// search in each line of list
lock(SyncObjects.ListSyncer)
{
for(int i=0; i < sourceList.Count; i++)
{
// get line from list
var str = sourceList;
// check if line contains text, if there are matches return "yes"
if (str.Contains(textContains))
return "yes";
}
}
// ifnothing found return "no"
return "no";
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
You should change only name of list
project.Lists["MasterCityList"];
the same is for variable
 

emperorjones

Новичок
Регистрация
18.09.2014
Сообщения
27
Благодарностей
1
Баллы
3
I see. simple - Thanks!!
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)