I hope somebody can help me with my issue.
My actual workflow to get add a new item to my list in SharePoint looks like this:
using (var clientContext = new ClientContext(Website))
{
List oList = clientContext.Web.Lists.GetByTitle("List");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
//add Item
ListItem listItem = oList.AddItem(itemCreateInfo);
listItem["Effort"] = 5.0;
listItem["ItemStart"] = DateTime.Now.ToLocalTime();
listItem["Workpackage"] = "PRG";
listItem.Update();
clientContext.ExecuteQuery();
}
Pretty straight forward and it "works" except for the Item: listItem["Workpackage"] = "PRG";
If I fetch the list to show me all values in item.FieldValues I get that this is a FieldLookUpValue. I display it like so ((FieldLookupValue)value.Value).LookupValue.
My problem is, that I need to set this value to the item I add to the list because without it SharePoint doesn't recognize it in the right field.
If I use the code above I get that this field ["Workpackage"] is maybe write-protected or that I transferd the wrong data for this field. Thats why I think that I have to transfer the data as a LookUpValue, but I really don't get how to make this work.
I hope I could describe my problem as close as possible.
If you need any further information, please let me know.
And thanks for the help anyway!
Best Regards
Please have a look here: https://sharepoint.stackexchange.com/questions/73252/sharepoint-client-model-and-setting-up-lookup-field
You need to pass the ID of the item from the lookup list.
Related
I create work items through the TFS api.
var type = project.WorkItemTypes["Bug"];
var workItem = new WorkItem(type)
{
History = "Created by OneTrueError incident #" + dto.OneTrueErrorIncidentId,
Title = dto.Title,
Description = dto.StackTrace,
};
workItem.Fields["Activity"].Value = dto.Activity;
workItem.Fields["Repro Steps"].Value = dto.StepsToReproduce;
workItem.Links.Add(new Hyperlink(someBaseUri + "/issue/" + dto.OneTrueErrorIncidentId));
workItem.Save();
At a later point I want to be able to fetch a specific work item by querying on a Hyperlink that I attached when creating the work item.
I can't figure out how to write that query. All examples I've found regarding links are for links to other work items or TFS resources. I have had no luck trying to modify those examples.
So how can I find a specific workitem using WIQL and a specific Hyperlink.Location?
Unfortunately, it's not able to directly use hyperlink url info in WIQL. You could only use Hyperlink Count field which returns the number of hyperlinks that are defined for the work item.
Reference Name=System.HyperLinkCount, Data type=Integer
As a workaround you may have to get a list of worktiems with links and go through all returned info to match the url that your attached when creating the work item. Then get the work item.
Hello im currently trying to fix so that my listview displays 2 columns, one which displays the tweet and the second one displaying the tweets owner(the user). how do i do this? i've come this far:
private void button1_Click(object sender, EventArgs e)
{
listbox1.Items.Clear();
tweetid.Items.Clear();
TwitterSearchResult inc = service.Search(new SearchOptions { Q = "stuff", Lang = "en" });
IEnumerable<TwitterStatus> status = inc.Statuses;
foreach (var tweet in inc.Statuses)
{
ListViewItem item = new ListViewItem(tweet.Text);
item.SubItems.Add(tweet.Text);
item.SubItems.Add(tweet.Text);
listView2.Items.Add(item);
I sorta want to include a new Tweetsharp command in the same variable "tweet". Is this possible. im thinking i have to add a new IEnumerable<>.
Any help would be thankfully accepted.
OH AND ONE MORE THING! :)
How come that tweetsharp only returns a 100 tweets max? Is there a way to solve this too? :)
Thanks.
one which displays the tweet and the second one displaying the tweets owner(the user)
Well, taking a quick look at the objects you're using, it appears that TwitterStatus has a User property of type TwitterUser, which itself has a Name property. Does the intellisense disagree with this?
im thinking i have to add a new IEnumerable<>
Why? You currently have a collection of TwitterStatus objects, which seem to contain all the information you need. Are you just looking to do this?:
item.SubItems.Add(tweet.Text);
item.SubItems.Add(tweet.User.Name);
From that collection (IEnumerable<>) of TwitterStatus objects you are able to extract all the information about those tweets. Just display the information you want to display.
So I'm creating a SharePoint 2010 project in Visual Studio that contains a Sequential Workflow (Farm Solution only) item that is associated with a certain list so that when an item is added to the list the workflow starts.
My question is, say an item was added in the following format:
Name | Email
Dave | dave#dave.com
Is there a way, programatically, to store this data in variables? As is, without using any hardcoded indexes or anything, just programatically have it so that I can pull this data and store it in two C# variables (int iD, string emailAddress) and the workflow knows which list item kicked it off?
At the moment the way I'm doing it is:
using (SPWeb oWeb = SPContext.Current.Web) {
SPList oList = web["List Name"];
string name = list.Items[(oList.ItemCount - 1)]["Name"].ToString();
}
But I'd rather not use indexers as there's a chance that the index is off if another item is added rapidly and if the list is reordered then ... disaster.
Thanks in advance!
Solved it guys! Very stupid of me to overlook this, but here is the solution:
C# creates a workflowProperties variable for you of type SPWorkflowActivationProperties which contains all the methods and properties to get the data you need:
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties(); // auto generated code.
Then to get the list item data or even list data all you do is:
SPList oList = workflowProperties.List; // get the list that contains the list item on which the workflow instance is running.
SPListItem oItem = workflowProperties.Item; // get the list item on which the workflow instance is running.
So to get my "Name" data I would've had to:
string name = workflowProperties.Item["Name"].ToString();
Hope this helps someone, although fortunately nobody is as stupid as me so you guys will probably figure it out yourself.
I hope there is someone who can help me out here. I have found an article which gives you the short piece of code to add Add Multiple Entities (Members) to a Marketing List. So far so good. I'm coming across this problem. I have a custom lookup field which gets another marketing list (has contacts, accounts or leads) inside the marketing member list. Now I need to migrate (add) those members into my new marketing list. The code I have:
1. AddListMembersListRequest request = new AddListMembersListRequest();
2. request.ListId = Origmarketing_List_Id.Id;
3. request.MemberIds = new Guid[1];
4. request.MemberIds[0] = guid;
5. AddListMembersListResponse resp = (AddListMembersListResponse)service.Execute(request);
Line 2 is the ID I get from the EntityReference(Look Up field getting another Marketing List), now the third and fourth line I'm setting is something I'm really confused about but still I'm sure I'm going right here because I'm setting it to the listmemberid. In this example I just had one cause I wanted to try out how it works. The guid in line 4 bdw gets the right value, it is declared at the top of my code(and I have output it on another field just to check it grabs the right value). Also can someone please show how you would do this when you want to add multiple entities? Thanks. I'm registering my plugin on pre-operation(Create). And the plugin itself doesn't fire any errors, but it just doesn't seem to add any members on my new list. I would really much appreciate if somone could help me out here. Thank You Really Much in Advance.
First of all, change event to post-operation, because you don't have the GUID of created entity yet, as a matter of fact you dont have the entity itself as well that's why it's called pre-operation.
To add multiple entities try pass a GUIDs array like in code bellow:
// Setup the CrmConnection and OrganizationService instances
CrmConnectionInstance = new CrmConnection(ConfigurationConstants.CrmConnectionName);
OrgServiceInstance = new OrganizationService(CrmConnectionInstance);
// Create the marketing list
Guid NewMarketingListId = Guid.Empty;
Microsoft.Xrm.Sdk.Entity CurrentList = new Microsoft.Xrm.Sdk.Entity(MarketingListConstants.MarketingListEntityName);
CurrentList[MarketingListConstants.MarketingListTypeAttribute] = false;
CurrentList[MarketingListConstants.ListNameAttribute] = "NameOfList";
// For contacts, a value of 2 should be used.
CurrentList[MarketingListConstants.CreatedFromCodeAttribute] = new OptionSetValue(2);
// Actually create the list
NewMarketingListId = OrgServiceInstance.Create(CurrentList);
// Use the AddListMembersListRequest to add the members to the list
List<Guid> MemberListIds = new List<Guid>();
// Now you'll need to add the Guids for each member to the list
// I'm leaving that part out as adding values to a list is very basic.
AddListMembersListRequest AddMemberRequest = new AddListMembersListRequest();
AddMemberRequest.ListId = NewMarketingListId;
AddMemberRequest.MemberIds = memberIds.ToArray();
// Use AddListMembersListReponse to get information about the request execution
AddListMembersListResponse AddMemberResponse = OrgServiceInstance.Execute(AddMemberRequest) as AddListMembersListResponse;
I'm trying to simply add a simple text or hyperlink field to a list item in sharepoint 2007.
I can add the field no problem:
list.Fields.Add("MyField",SPFieldType.Text, false);
And it shows up fine on my list items.
However no matter which way I try, I can't programmatically set a value for the field. I tried:
list.items[0]["MyField"] = "text";
and I tried loading into a field:
SPField field = list.items[0].Fields["MyField"];
and setting it there, and setting the default value and updating, but nothing what so ever happens.
I always finish my code blocks with list.update(); or if I'm operating on the item itself item.update(); so I'm not at least missing that. Can anyone tell me what I'm doing wrong?
Thanks
Try:
SPListItem item = list.items[0];
item["MyField"] = "text";
item.Update();
Although it seems equivalent, the above code is not the same as:
list.items[0]["MyField"] = "text";
list.items[0].Update();
For more information, see here and here for people who have documented the same behavior.
Could you try this for adding a new field and setting a default value? Untested code. let me know how it goes.
SPFieldText fldName = (SPFieldText)list.Fields.CreateNewField(SPFieldType.Text.ToString(), "mycolumn");
fldName.DefaultValue = "default";
list.Fields.Add(fldName);
list.Update();
I've always found the best route is to get a reference to the list item directly and update specifically, as opposed to using the indexer route. Just like rich's first example mentions.
http://www.sharepointdevwiki.com/display/public/Updating+a+List+Item+programmatically+using+the+object+model
From all the discussion above it appears that you are trying to set the field value in a list event handler and you are setting the value in item adding or item updating event. If this is the case then you need to consider AfterProperties. Remember we have *ing and *ed events and in case of *ing events we need to work with BeforeProperties and AfterProperties.
I hope this helps!