Links

104 - Options Generators & Generic API Requests

Introduction

In Rewst 104, we will delve into the intricacies of option generators and generic API requests. Specifically, we will learn how option generators enhance forms, building upon the knowledge acquired in our Rewst 102 course. Additionally, we will explore generic API requests by integrating Microsoft Graph API, demonstrating its functionality within the Rewst platform. We will also implement list comprehension techniques, building upon the concepts introduced in Rewst 103.
When you've completed this training, don't forget to get credit!

Watch the video or follow along with the steps below

These steps assume you have completed the full steps from Rewst 102 You can find the instructions to make this form on the Rewst 102 Page.

Understanding Option Generators

In this course, we will filter groups based on user membership status. When adding a user to a group, only groups the user is a member of will be displayed. Conversely, when removing a user from a group, only groups the user is a member of will be shown. To achieve this, we will utilize option generators, specialized workflows that curate form field options dynamically.

Modifying the Form

We'll start by modifying our existing form from Rewst 102. The group field and add/remove field positions will be switched. When users select a user and the add/remove radio button, these values will be passed to our option generator workflow.
Step 1: Modify the Form Created in Rewst 102
Open the Form
  1. 1.
    Go to AutomationsForms in the menu.
  2. 2.
    Search for the Add or Remove from AzureAD Group Form.
  3. 3.
    Click on the Form to Open it.
Re-order the Form
  1. 1.
    Drag and Drop the Add or Remove Field above Group.
  2. 2.
    Click the Save button at the top right of the form builder.
  3. 3.
    Click Submit on the pop-up to confirm.

Creating the Option Generator

In our next steps, we'll go to the Workflow section. Here, we'll craft a new workflow called "Demo Option Generator for Groups Based on User Membership." This workflow will be configured as an option generator, with specified inputs including user ID and action (add or remove). Moreover, we'll set the output configuration variable as "options" for our subsequent tasks.
Step 2: Create a New Option Generator Workflow
Create a New Workflow
  1. 1.
    Go to AutomationsWorkflows in the menu.
    • You can open this in a new tab to make it easier.
  2. 2.
    Click Create at the top right to add a new Workflow.
  3. 3.
    Type Option Generator for Groups based on User Membership for the name.
  4. 4.
    Click Submit.
Add Output Configuration in Workflow Variables
  1. 1.
    Click on Configure Workflow Variables (The Pencil icon) at the top right of the Menu.
  2. 2.
    Choose Option Generator for the Workflow Type dropdown.
  3. 3.
    Click on the Add (+) button next to Output Configuration at the bottom.
  4. 4.
    Type options for the Field Name.
  5. 5.
    Click Submit.
Add Input Configuration Variables
  1. 1.
    Click on the Add (+) button next to Input Configuration.
  2. 2.
    Type action for the name.
  3. 3.
    Click Required.
  4. 4.
    Click on the Add (+) button next to Input Configuration again.
  5. 5.
    Type user_id for the name.
  6. 6.
    Click Required.
  7. 7.
    Click Submit.
Step 3: Add the List Member Actions to Option Generator Workflow
Add a Core Noop Action to the Canvas
  1. 1.
    Drag and Drop the noop action to the Workflow Canvas.
    • You can find this in the Core section or by searching.
  2. 2.
    Click on the noop to open the Details menu.
  3. 3.
    Click the edit button next to core_noop.
  4. 4.
    Rename the action to add_or_remove.
  5. 5.
    Click Advanced.
  6. 6.
    Choose the Follow First Transition Mode.
Create a Transition for Adding a User
  1. 1.
    Click on the default On Success transition on the add_or_remove noop.
  2. 2.
    Type Add for the Custom Label.
  3. 3.
    Click the Custom Condition button from the Condition options.
  4. 4.
    Click the Source button next to the Custom Condition field.
  5. 5.
    Type {{ CTX.action == "add" }} in the editor.
  6. 6.
    Close the editor.
Create a Transition for Removing a User
  1. 1.
    Click the Add (+) button next to the Add transition.
  2. 2.
    Type Remove for the Custom Label.
  3. 3.
    Click the Custom Condition button from the Condition options.
  4. 4.
    Click the Source button next to the Custom Condition field.
  5. 5.
    Type {{ CTX.action == "remove" }} in the editor.
Add a Graph API Request action to List Member Groups
  1. 1.
    Drag and Drop the Graph API Request action to the Workflow Canvas.
    • You can find this in the Microsoft Graph section or by searching.
  2. 2.
    Click on the new action to open the Details menu.
  3. 3.
    Click the edit button next to the name.
  4. 4.
    Rename the action to list_user_groups.
Add API Information to the List User Groups Action
It is recommended that you reference the API Docs These docs are references in this portion of the training
  1. 1.
    Click the Source button next to the Endpoint field.
  2. 2.
    Add /users/{id | userPrincipalName}/memberOf from the API docs to the editor.
  3. 3.
    Replace {id | userPrincipalName} with {{ CTX.user_id }} so it looks like the following:
    /users/{{ CTX.user_id }}/memberOf
  4. 4.
    Close the editor.
  5. 5.
    Click and Drag the transition from the add_or_remove action to the list_user_groups action.
    • To do this, you will need to hover over the circle under the Remove section of the action.
Add a Graph List Groups action to List All Groups
  1. 1.
    Drag and Drop the List Groups action to the Workflow Canvas.
    • You can find this in the Microsoft Graph section or by searching.
  2. 2.
    Click on the action to open the Details menu.
  3. 3.
    Click the edit button next to name.
  4. 4.
    Rename the action to list_all_groups.
Add a Data Alias to the List All Groups action
  1. 1.
    Click on the On Success transition.
  2. 2.
    Click on the Add (+) button next to Data Aliases.
  3. 3.
    Type all_groups as the key.
  4. 4.
    Open the Source editor.
  5. 5.
    Add the following to the editor:
{{ RESULT.result.data.value }}
  1. 6.
    Close the editor.
  2. 7.
    Click and Drag the transition from the add_or_remove action to the list_all_groups action.
    • To do this, you will need to hover over the circle under the Add section of the action.
Add a Data Alias to the List User Groups action
  1. 1.
    Click on the On Success transition of list_user_groups.
  2. 2.
    Click on the Add (+) button next to Data Aliases.
  3. 3.
    Type group_list as the key.
  4. 4.
    Open the Source editor.
  5. 5.
    Add the following to the editor:
    {{ RESULT.result.data.value }}
  6. 6.
    Close the editor.
Copy the List User Groups Action
  1. 1.
    Click on the options menu next to the list_user_groups action.
  2. 2.
    Click Create Copy.
  3. 3.
    Move it on the Canvas under the list_all_groups action.
  4. 4.
    Drag the Transition from list_all_groups to the list_user_groups copy.
  5. 5.
    Click on the On Success Transition for the new copy.
  6. 6.
    Change the Data Alias from group_list to user_groups.
Add a Final Noop to Build the Group List
  1. 1.
    Add a core_noop action under the list_user_groups action.
  2. 2.
    Click on the action to open the Details menu.
  3. 3.
    Change the name to build_group_list.
  4. 4.
    Click the On Success Transition.
  5. 5.
    Click on the Add (+) button next to Data Aliases.
  6. 6.
    Type group_list as the key.
  7. 7.
    Open the Source editor.
  8. 8.
    Add the following Jinja to the editor:
    {{
    [
    group
    for group in CTX.all_groups
    if group.id not in [
    user_group.id
    for user_group in CTX.user_groups
    ]
    ]
    }}
  9. 9.
    Close the editor.
Add the Final Transition
  1. 1.
    Drag the Transition from list_user_groups to the build_group_list copy.
  2. 2.
    Click Publish.
  3. 3.
    Click Submit.

Trigger and Integration

Next, we'll first add a trigger, configured to always pass, guaranteeing the workflow's execution when necessary inputs are supplied. Following that, we'll integrate the option generator into the group field within the form. To ensure clarity, we'll specify the display name attribute for the label field, ensuring that the options appear as group names for user selection.
Step 4: Update the options Config and add the Trigger
Open the Workflow Variables
  1. 1.
    Click on Configure Workflow Variables (The Pencil icon) at the top right of the Menu.
  2. 2.
    Open the source editor next to the options Output Configuration.
  3. 3.
    Type the following:
    {{ CTX.group_list }}
  4. 4.
    Click Submit.
Add and Configure the Trigger
  1. 1.
    Click Add Trigger in the top menu.
  2. 2.
    Type Option Generator for the Name.
  3. 3.
    Click the slider next to Enabled.
  4. 4.
    Choose Core - Always Pass Trigger Type.
  5. 5.
    Click the slider next to All current and future managed organizations.
  6. 6.
    Click the Add (+) button next to Integration Overrides.
  7. 7.
    Choose Microsoft Graph for the Integration dropdown.
  8. 8.
    Click Submit.
    • You may need to Click Cancel after to close it.
  9. 9.
    Click Publish at the top right of the workflow.
  10. 10.
    Click Submit.
Step 5: Update the Form to be a Workflow Generated Form
Change the Group field to Workflow Generated
  1. 1.
    Go to AutomationsForms in the menu.
    • If you already have another tab open, go back to your form.
  2. 2.
    Open the Add or Remove from AzureAD Group Form.
  3. 3.
    Click on the Group field.
  4. 4.
    Click the slider under Workflow Generated.
Configure the Details of the Workflow Generated Field
  1. 1.
    Select the Option Generator for Groups based on User Membership Workflow from the dropdown.
    1. 1.
      Refresh the page if the workflow does not appear.
  2. 2.
    Replace the Label Field default with displayName.
  3. 3.
    Choose Option Generator for the Trigger.
  4. 4.
    Click Populate from form field under the schema.enumSourceWorkflow.input.action field.
  5. 5.
    Choose action from the dropdown.
  6. 6.
    Click Populate from form field under the schema.enumSourceWorkflow.input.user_id field.
  7. 7.
    Choose user_id from the dropdown.
  8. 8.
    Click Save.
  9. 9.
    Click Submit.
Run the Form to Pull the Options Generator
  1. 1.
    Click on View Usages at the top right.
  2. 2.
    Click on the View Direct URLs.
  3. 3.
    Click on the link.
⚠️ You will not see the link if you haven't completed Rewst 102 The link shows up because the Workflow built in 102 has the Form set as a trigger. You can find the instructions to make this workflow on the Rewst 102 Page
Step 6: Test it!
Try it for yourself!
  1. 1.
    Choose a User.
  2. 2.
    Click Add or Remove.
  3. 3.
    Check to see if the groups show correctly!

Conclusion

Congratulations! You've successfully configured an option generator and implemented logic using generic API requests and list comprehension techniques. With this knowledge, you can enhance your forms and streamline group management.

Get Credit

To get credit for completing this session offline, please submit this form.

Additional Resources

For more information on using Options Generators, Generic API Requests, List Comprehension, and more, check out our documentation:

Need more guidance?

Sign up for our LIVE training sessions below!
Last modified 3mo ago