我可以在SharePoint中使用Visual Studio循环列表吗? [英] Can I loop a list in SharePoint with Visual Studio?

查看:96
本文介绍了我可以在SharePoint中使用Visual Studio循环列表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(使用SharePoint 2010)

(Using SharePoint 2010)

大家好,我会尽量提供足够的背景信息,使之有意义.

Hi guys, I'll try to give enough background for this to make sense.

基本上,我们有一个客户列表以及他们的电话号码和其他信息.该列表按过期日期排序.我们有电话推销员会在此列表中致电客户.到目前为止,我们只有一位电话推销员在列表中呼叫客户,这没有任何问题.但是现在,我们希望在列表中有两个tm的主叫客户,并且将来可能还会更多.当然,问题在于我们不希望他们同时致电相同的客户.

Basically we have a list of customers with their phone numbers and other info. This list is sorted by an overdue date. We have telemarketer staff that call the customers in this list. So far we've had only one telemarketer calling the customers in the list which presents no problems. Now however we want to have two tm's calling customers in the list, and possibly more in the future. Of course the problem is we don't want them calling the same customers at the same time.

我们可以通过将tm分配给列表中的每个客户来解决此问题,然后他们只会看到分配给他们的客户.但是,由于我们要按一定的顺序调用它们,因此我们也希望按顺序分配tm,例如:

We can solve this by assigning tm's to each customer in the list, then they only see the customers they are assigned to. But since we want to call them in a certain order we would want to assign the tm's in order as well, for example:

假设我们有3个tm的电话.理想情况下,该列表如下所示(TM1、2和3是将分配给该客户的tm):

Assume we have 3 tm's calling. The list would ideally look as follows (TM1, 2, and 3 are the tm's that would be assigned to that customer):

  • 成本#1-TM1
  • Cust#2-TM2
  • Cust#3-TM3
  • Cust#4-TM1
  • Cust#5-TM2
  • Cust#6-TM3
  • Cust#7-TM1
  • Cust#8-TM2 ...等等.
  • Cust#1 - TM1
  • Cust#2 - TM2
  • Cust#3 - TM3
  • Cust#4 - TM1
  • Cust#5 - TM2
  • Cust#6 - TM3
  • Cust#7 - TM1
  • Cust#8 - TM2 ... and so on.

现在的诀窍是,有时我们可能会打电话1 tm,或者打电话3 tm.因此,每天早上,tm管理员必须将呼叫分配给不同的tm.当列表中有1000多个cusomters时,这变得很棘手.当然,我们可以将列表切换到数据视图,然后从Excel工作表中复制和粘贴值以进行分配.或者我们可以在Access中打开它并对其运行脚本.但是,有没有一种方法可以在Visual Studio中为工作流程(或其他方法)编程,以为我循环遍历列表并执行此操作?我需要为其提供一个数字,该数字表示将要呼叫多少tm,然后它将遍历客户列表并以上述指定的方式分配tm.

Now the trick is that some days we may have 1 tm calling, or 3 tm's calling. So each morning before they begin the tm admin would have to assign the calls to different tm's. This get's tricky when there's 1000+ cusomters in the list. Sure we could switch the list to data view and copy and paste values in from an Excel sheet to make the assignments. Or we could open it in Access and run a script against it. But is there a way I could program a workflow (or something) in Visual Studio to loop through the list for me and do this? I would need to provide it a number representing how many tm's would be calling and then it would loop through the list of customers and assign the tm's in the fashion designated above.

如果您能想到一种更好的方法,那么我也欢迎其他想法.预先感谢!

If you can think of a better way to do this I'm open to other ideas too. Thanks in advance!

推荐答案

您绝对可以遍历列表中的项目.这是您可以使用的一种方法的示例:

You can absolutely loop through the items in a list. Here's an example of one way you could do it:

string[] tms = new string[] { "TM1", "TM2", "TM3" };

SPList list = SPContext.Current.Web.Lists["My List"];
SPListItemCollection items = list.Items;

for (int i = 0; i < items.Count; i++)
{
    SPListItem item = items[i];
    item["AssignedTM"] = tms[i % tms.Length];

    item.Update();
} 

剩下的唯一问题是如何执行此代码.您可以将其放在控制台应用程序中并在服务器上运行(不推荐),也可以将其放在Webpart中,粘贴在页面上,授予管理员对该页面的访问权限(可能带有随附的表单),以及(每天)(或在数据更改时)执行该操作.

The only question that remains is how to execute this code. You could put this in a console application and run it on the server (not recommended), or you could put it in a webpart, stick it on a page, grant the admin access to the page (perhaps with an accompanying form), and have (him/her) execute it daily (or when the data changes).

这篇关于我可以在SharePoint中使用Visual Studio循环列表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆