How to use and Why to use Workflow Input variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:26 PM
Hello all,
Good morning.
I have a catalog item with few variables created and a workflow is attached.
But I also created a variable by clicking Edit Inputs on the workflow.
Can someone tell me what is the use of creating this variable and how to access this inside workflow?
A scenario would be better to understand this.
Note: Variables are shown on the cat item form. But where this variable is shown?
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 08:36 PM
Hi @Lucky1 ,
In ServiceNow, when you create variables in the context of a workflow by clicking "Edit Inputs," you are creating workflow variables. These are distinct from catalog variables and are specific to that particular workflow. Here's a breakdown:
1. **Catalog Variables:**
- **Usage:** These are typically used in Service Catalog items to capture information from users during request creation.
- **Access:** Catalog variables are displayed on the catalog item form when users are requesting a service.
- **Example Scenario:** If you have a catalog item for requesting a new laptop, the catalog variables might include fields like "Laptop Model" and "Quantity."
2. **Workflow Variables (Created via "Edit Inputs" in a Workflow):**
- **Usage:** These variables are specific to the workflow and are used to capture data within the workflow context.
- **Access:** Workflow variables are primarily used within the workflow activity and are not exposed to end-users on the catalog item form.
- **Example Scenario:** In a workflow for processing a service request, you might have a workflow variable to store the approval status or to store data temporarily during the workflow execution.
**Scenario Example:**
- Let's say you have a workflow for employee onboarding.
- Catalog Variables: On the catalog item form, you collect information like "Employee Name," "Department," and "Position."
- Workflow Variables: In the workflow, you might have a variable like "OnboardingStatus" to track the progress of the onboarding process. This variable is used internally within the workflow to manage the state of the onboarding request.
**Accessing Workflow Variables in a Workflow:**
- Workflow variables are accessible within the workflow activities.
- To use a workflow variable in a script or condition, you can reference it using the `current` object. For example:
var onboardingStatus = current.variables.onboarding_status;
**Note:**
- Workflow variables are not intended to be shown on the catalog item form. They serve a different purpose, mainly for internal data management within the workflow.
When designing workflows, consider using workflow variables for information that is relevant and crucial within the workflow process but doesn't need to be exposed to users filling out catalog items. Always test your workflows thoroughly in a non-production environment to ensure they behave as expected.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 09:49 PM
Hello Danish,
Thank you very much for great explanation.
But what is this and where do we use this below line of code?
var readValue = workflow.inputs.variable_name;
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 07:37 PM
Hi @Lucky1 ,
workflow.inputs is used in sub-workflows when you call sub-workflow from main workflow and send some values to sub-workflow.
Thanks,
Danish