I got a task i.e i want to get data from one list column to another list, i want to show that data in choice field of that at the time of adding new item .
Here I am having data in list named “city” . it is having two fields “ cityname” and “statename” .

I am having one more list i.e “ cityname” .
I am created two columns “citynames “ and “ statename” with choicefileds . I want to get data of “cityname “column in the first list “ city “ to the column “ citynames” to the second list “ cityname” and to get data of “statename “column in the firstlist “ city “ to the column “ statename” to the list “ cityname” when ever an item created in secondlist “ cityname” like below screen



So for getting data just I have written vb.code as below .
Dim spsite As SPSite = New SPSite("http://pc00026:1364/test1")
Dim spweb As SPWeb = spsite.OpenWeb()
spweb.AllowUnsafeUpdates = True
Dim splists As SPListCollection = spweb.Lists
Dim splist As SPList = splists("city")
Dim states As New ArrayList
Dim citys As New ArrayList
Dim items As SPListItemCollection = splist.Items
Dim item As SPListItem
For Each item In items
If Not states.Contains(item("statename")) Then
states.Add(item("statename"))
End If
citys.Add(item("cityname"))
Next
Dim stalist As SPList = splists("cityname")
Dim regionField As SPFieldChoice = stalist.Fields("statename")
Dim cityregionField As SPFieldChoice = stalist.Fields("citynames")
For i As Integer = 0 To states.Count - 1
If Not regionField.Choices.Contains(states(i)) Then
regionField.Choices.Add(states(i))
End If
Next
regionField.DefaultValue = "Select"
regionField.Update()
For j As Integer = 0 To citys.Count - 1
If Not cityregionField.Choices.Contains(citys(j)) Then
cityregionField.Choices.Add(citys(j))
End If
Next
cityregionField.DefaultValue = "Select"
cityregionField.Update()
up to this it is working fine … but if we add new item in first list “city” i.e data does not reflects in second list drop downs . for that when ever we add item in the first list , I run a workflow , this workflow updates the data in dropdowns of second list i.e “ citynames” .
for developing workflow I used visual studio 2008 . in that I have taken sequential workflow template.
And I named that project as” getingdataindropdown1”

And pass the URL where u want to create workflow .and click next

Next select library or list where u want to deploy u r workflow i.e in my application it is “city” .and click next .


Check “ when an item is created “ checkbox . and finsh
In the design i.e “workflow1.vb(design) ” . drop “code” control from the Toolbox .

Double click on the codeactivity1 and write code as below .
Private Sub codeActivity1_ExecuteCode(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Dim context As SPContext
Dim spsite As SPSite = New SPSite("http://pc00026:1364/test1")
Dim spweb As SPWeb = spsite.OpenWeb()
spweb.AllowUnsafeUpdates = True
Dim splists As SPListCollection = spweb.Lists
Dim splist As SPList = splists("city")
Dim states As New ArrayList
Dim citys As New ArrayList
Dim items As SPListItemCollection = splist.Items
Dim item As SPListItem
For Each item In items
If Not states.Contains(item("statename")) Then
states.Add(item("statename"))
End If
citys.Add(item("cityname"))
Next
Dim stalist As SPList = splists("cityname")
Dim regionField As SPFieldChoice = stalist.Fields("statename")
Dim cityregionField As SPFieldChoice = stalist.Fields("citynames")
For i As Integer = 0 To states.Count - 1
If Not regionField.Choices.Contains(states(i)) Then
regionField.Choices.Add(states(i))
End If
Next
regionField.DefaultValue = "Select"
regionField.Update()
For j As Integer = 0 To citys.Count - 1
If Not cityregionField.Choices.Contains(citys(j)) Then
cityregionField.Choices.Add(citys(j))
End If
Next
cityregionField.DefaultValue = "Select"
cityregionField.Update()
End Sub.
AND DEPLOY THE SOLUTION .
You will find u r workflow in workflow settings of your list i.e “ city”
This workflow runs when an item is created and updates the newly added item data to the list “cityname”
