<< Click to Display Table of Contents >> Navigation: Custom Actions > Variables > How to set dynamic values for variables > Invoke Web Service |
Web service call could return simple text or xml text or JSON text as output. We can store either of these output values as text values in variables or we can use functions like $xpath() or $jsonpath() functions to extract the required values and store them in the variables for later use.
If we use $xpath() function that returns array of objects then we can use the variable that stores this function return value and run for this variable to create multiple items. If the function returns single text value for the given xpath expression, then we can use this variable only in column mappings.
Example Web Service Call Result:
<Cities>
<City id="1">Hyd</City>
<City id="2">Bng</City>
<City id="3">Delhi</City>
</Cities>
Sample Usage of Result:
Expression 1: $xpath(WebServiceActionName##Value,/Cities)
Output (Array of Objects):
Output1: [Cities: "<City id="1">Hyd</City><City id="2">Bng</City><City id="3">Delhi</City>"]
Output2: <City id="1">Hyd</City>
<City id="2">Bng</City>
<City id="3">Delhi</City>
Please note that $xpath() function internally contains two different output values as showed in above example. In this example, Output 1 is JSON object and it will be used in “Run for” in Create item Action. Output 2 is simple text and will be used in column mappings.
Expression 2: $xpath(WebServiceActionName##Value,/Cities/City[1])
Output (Simple Text):
Output1: {id: 1, City: Hyd}
Output2: Hyd
Similarly, if we use $jsonpath() function that returns multiple objects then we can use the variable that stores this function return value and run for this variable to create multiple items. If the function returns simple text then we can use this only in column mappings.
Refer $xpath() and $jsonpath() functions for more details.
Using the “Define Variable Mappings” section in the Invoke Web Service action settings page, we can assign current action values to variables using syntax defined below (See screenshots below).
Variable value Supports following types
•Literal/Custom values
•Another field values (Place holders of current item and query list item actions that are executed before this web service action are supported)
•Functions
Syntax for defining variable with Invoke Web Service action placeholders within same action: {CurrentAction}##Value
In Add/Update action you can run for 'varUsers' variable and update column values using syntax:
@{CollectionValue}first_name
@{CollectionVaue}Id
Syntax for invoke web service action result value if used in another action column mapping or variable mapping: {Invoke Web Service Action name}##Value
Example: Users##Value