Monday, November 11, 2013

SharePoint 2013 workflow Call an external web service

SharePoint 2013 workflow Call an external web service
http://code.msdn.microsoft.com/office/SharePoint-2013-workflow-48ea87d4

vs2012 -> file -> new -> project c# -> office/SharePoint -> apps -> apps for SharePoint 2013 -> "CompleteCustomerDetails"

CompleteCustomerDetails -> Right Click -> New Item -> select 'List' template -> give name as "Customers"

CompleteCustomerDetails -> double click "Customers"
Now go to Column tab and add three new columns as follows and after delete default "Title' column.
CustomerId(Single Line of Text)(Required)
Address(Single Line of Text)(Required)
City(Single Line of Text)(Required)

CompleteCustomerDetails -> Right Click -> Add -> New Item -> select 'Workflow' Template -> give name it as "CompleteCustomerDetailsWorkflow"

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
By default one control flow Sequence is their. Rename it as 'Root'
Now drag and drop four "Sequence" from "Control Flow" from "ToolBox". for four 'sequence' put name as follows.
1. Init
2. Get Customer Data from Northwind
3. Process Response
4. Update Customer Item

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Select 'Root' sequence and click on 'Variables' Tab and create custom variables as follows

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> Init (sequence)
Select 'Init' sequence and click on 'Variables' Tab and create custom variables as follows

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> Init (sequence)
And drag and drop "LookUpSpListItem" from "SP-List" section from toolbox.

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> Init (sequence)
And grag and drop "GetDynamicValueProperties" from "DynamicValue" section from toolbox

click on "GetDynamicValueProperties" Properties elapses button, it will open one popup button. select values as follows

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Get Customer Data from Northwind" (sequence)
Select "Get Customer Data from Northwind" sequence and click on 'Variables' Tab and create custom variables as follows

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Get Customer Data from Northwind" (sequence)
And drag and drop "Assign" into "Get Customer Data from Northwind" section from "Primitives' section from toolbox.
And set the "To" Property as NorthwindServiceUri and "Value" property as "http://services.odata.org/Northwind/Northwind.svc/Customers('" + CustomerId + "')?$format=json"

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Get Customer Data from Northwind" (sequence)
And drag and drop "HttpSend" into "Get Customer Data from Northwind" section after "Assign" section from "Messaging' section from toolbox.
HttpSend Properties
Method : GET
Uri : NorthwindServiceUri
ResponseContent : NorthwindServiceResponse

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Process Response" (sequence)
And drag and drop "GetDynamicValueProperties" into "Process Response" section from "DynamicValue' section from toolbox.
set the "GetDynamicValueProperties" properties as follows
Properties         : click on ellipsis button 
Source : NorthwindServiceResponse

Name : CustomerName
City         : CustomerCity
       Address : CustomerAddress


CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Update Customer Item" (sequence)
And drag and drop "UpdateListItem" from "SP-List" section from toolbox.
And set "UpdateListItem" properties as follows
ItemId : current item
List id : current list
ListItemPropertiesDynamicValue : click on elapses button

CompleteCustomerDetails -> CompleteCustomerDetailsWorkflow -> double click "Workflow.xaml"
Now Go to Workflow -> Root -> "Update Customer Item" (sequence)
And drag and drop "WriteToHistory" from "SP-Utility" section from toolbox.
And set "WriteToHistory" properties as follows
Message : "Customer updated."

CompleteCustomerDetails -> AppManifest.xml 
now go to "General" tab and find the start page and change the value as follows
start page : CompleteCustomerDetails/Lists/Customers/AllItems.aspx

CompleteCustomerDetails -> Right Click -> Deploy

now select "EASTC" item -> go to ribbon -> select Item tab -> go to workflow section and click on 'workflow'

now start "CompleteCustomerDetailsWorkflow - WorkflowStart"

after few seconds Address,Name,City columns are updated by workflow
Thank you.

No comments:

Post a Comment