Studio
2023.10
false
Banner background image
Studio User Guide
Last updated Apr 26, 2024

Using Coded automation in Low-Code workflow

In this tutorial, you can learn how to incorporate a coded automation called CodedResetAssetValue.cs into a low-code workflow. The CodedResetAssetValue.cs automation performs the following steps:
  1. Retrieves the current value of a specific asset from Orchestrator.
  2. Compares the retrieved asset value with the input value provided as an argument.
  3. If the previous asset value does not match the input value, it updates the asset value in Orchestrator.
  4. Logs messages that indicate the status of the asset value, whether it was updated or remained unchanged.
To use a coded automation inside a low-code workflow, first create the coded workflow, then invoke it in the low-code workflow using the Invoke Workflow File activity. Perform the following steps to incorporate a coded automation within a low-code workflow:
  1. Create a new coded workflow. For this example, name it CodedResetAssetValue.
    1. Give the following return arguments to the Execute method to indicate if the asset value was changed and to provide the asset value: (bool assetValueWasChanged, string assetValue)
    2. For the Execute method, add the following input parameters: assetName (string) and assetValue (string).
      public (bool assetValueWasChanged, string assetValue) Execute(string assetName, string assetValue)public (bool assetValueWasChanged, string assetValue) Execute(string assetName, string assetValue)
    3. Use the GetAsset API to retrieve the current value of the specified asset using the assetName parameter.
    4. Store the previous asset value in the previousAssetValue variable .
      var previousAssetValue = system.GetAsset(assetName).ToString();var previousAssetValue = system.GetAsset(assetName).ToString();
    5. Compare the previous asset value with the input asset value using the Equals method.
    6. If the values are equal, return (false, assetValue) to indicate that the asset value was not changed.
    7. If the values are different, use the SetAsset API to update the asset value to the input assetValue.
    8. Return (true, previousAssetValue) to indicate that the asset value was changed, along with the previous asset value.
    if (previousAssetValue.Equals(assetValue))
          {
            return (assetValueWasChanged: false, assetValue: assetValue);
          }
          else
          {
            system.SetAsset(assetValue, assetName);
            return (assetValueWasChanged: true, assetValue: previousAssetValue);
          }if (previousAssetValue.Equals(assetValue))
          {
            return (assetValueWasChanged: false, assetValue: assetValue);
          }
          else
          {
            system.SetAsset(assetValue, assetName);
            return (assetValueWasChanged: true, assetValue: previousAssetValue);
          }
  2. Create a low-code workflow. For this example, name it WorkflowUsingCodedAutomation.
  3. Add an Assign activity and assign a value to the assetValue variable.
  4. Add an Invoke Workflow File activity and invoke the CodedResetAssetValue.cs coded automation. Add the required arguments.
    Note: For Windows projects: In the Invoke Workflow File activity, select Browse for File and change the file extensions you're browsing for, from Workflow Files (*.xaml, *.uiwf) to All Files (*.*). This allows you to view all files, including .cs.


  5. Add an If activity, and log messages for the scenarios where an asset value remains unchanged, and for the scenario where an asset value is updated.


Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.