Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Updates & Insights
  • Questions
  • Learning
    • E-learning Courses
    • Empower Replay: Limited Edition
    • Tutorials
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
      • About the DevOps Program
      • DataMiner DevOps Support
  • Downloads
  • More
    • DataMiner Releases & Updates
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

How to receive a value of selected option in UIBlockType.DropDown

Solved1.88K views16th November 2023Automation Skyline.DataMiner.Automation UIBlockType
1
Curtis Baiden [DevOps Advocate]506 28th September 2023 1 Comment

I have tried to use the UIResult GetString() method and it works but the WasOnChange method always returns false. Can anyone confirm if there is better method to check event changes with a UIBlockType.DropDown.

Curtis Baiden [DevOps Advocate] Selected answer as best 16th November 2023
Curtis Baiden [DevOps Advocate] commented 2nd November 2023

this problem is solved now

3 Answers

  • Active
  • Voted
  • Newest
  • Oldest
1
Matthias Declerck [SLC] [DevOps Advocate]2.75K Posted 28th September 2023 4 Comments

Hi Curtis,

Back in the days when I implemented some enhancements/options on the dropdown in Interactive Automation, I used the following C# block as a base for my other test scripts.
It generates an information event when the value of a dropdown has changed.
Hope this helps!

using System;
using System.Collections.Generic;

using Skyline.DataMiner.Automation;

public class Script
{
    public void Run(Engine engine)
    {
        UIResults uir = null;

        string selectedVal = "option 3";
        List<string> dropDownOptions = new List<string>();
        for (int i = 0; i < 10; i++)
        {
            if (i % 2 == 0) //even = value, oneven = otion
            {
                dropDownOptions.Add(string.Format("value {0}", i));
            }
            else
            {
                dropDownOptions.Add(string.Format("option {0}", i));
            }
        }
        string extraOptions = String.Join(";", dropDownOptions);

        do
        {

            UIBuilder uib = new UIBuilder();
            uib.RequireResponse = true;
            uib.RowDefs = "a;25;a;25;a";
            uib.ColumnDefs = "150;200";

            uib.AddStaticText("Dropdown_Change+filter", 1, 0);
            uib.AddDropDown("cbBox4", selectedVal, dropDownOptions, 1, 1, width: 200, wantsOnChange: true, displayFilter: true);

            uib.AddButton("Close", "close", 3, 1, 170, 25);
            uir = engine.ShowUI(uib);

            if (uir.WasOnChange("cbBox4"))
            {
                selectedVal = uir.GetString("cbBox4");
                engine.GenerateInformation(string.Format("SELECTED DROPDOWN VALUE: {0}", selectedVal));
            }

        } while (!uir.WasButtonPressed("close"));
    }
}

public static class AutomationUIExtensions
{
    public const string InitialDropDownValue = "-Select-";

    #region Public Enums
    public enum UIBlockStyle { Title1, Title2, Title3 };
    public enum UIBlockHorizontalAlignment { Left, Center, Right };
    public enum UIBlockVerticalAlignment { Top, Center, Bottom };
    #endregion

    #region Public Methods
    public static void AddStaticText(this UIBuilder uib, string text, uint row, uint column, uint rowSpan = 1, uint columnSpan = 1, UIBlockHorizontalAlignment horizontalAlignment = UIBlockHorizontalAlignment.Left, UIBlockVerticalAlignment verticalAlignment = UIBlockVerticalAlignment.Center, string margin = "", bool isMultiLine = false)
    {
        UIBlockDefinition uibDef = new UIBlockDefinition();
        uibDef.Type = UIBlockType.StaticText;
        uibDef.Text = text;
        uibDef.Row = (int)row;
        uibDef.RowSpan = (int)rowSpan;
        uibDef.Column = (int)column;
        uibDef.ColumnSpan = (int)columnSpan;
        uibDef.HorizontalAlignment = GetHorizontalAlignment(horizontalAlignment);
        uibDef.VerticalAlignment = GetVerticalAlignment(verticalAlignment);
        uibDef.IsMultiline = isMultiLine;

        if (!string.IsNullOrEmpty(margin))
        {
            uibDef.Margin = margin;
        }

        uib.AppendBlock(uibDef);
    }

    public static void AddDropDown(this UIBuilder uib, string destVar, string initialValue, List<string> dropDownOptions, uint row, uint column, uint rowSpan = 1, uint columnSpan = 1, int width = -1, int minWidth = -1, int maxWidth = -1, int height = -1, int minHeight = -1, int maxHeight = -1, UIBlockHorizontalAlignment horizontalAlignment = UIBlockHorizontalAlignment.Left, UIBlockVerticalAlignment verticalAlignment = UIBlockVerticalAlignment.Center, string margin = "", bool wantsOnChange = false, bool displayFilter = false)
    {
        UIBlockDefinition uibDef = new UIBlockDefinition();
        uibDef.Type = UIBlockType.DropDown;
        uibDef.DestVar = destVar;
        uibDef.InitialValue = initialValue;
        uibDef.Row = (int)row;
        uibDef.RowSpan = (int)rowSpan;
        uibDef.Column = (int)column;
        uibDef.ColumnSpan = (int)columnSpan;
        uibDef.Width = width;
        uibDef.MinWidth = minWidth;
        uibDef.MaxWidth = maxWidth;
        uibDef.Height = height;
        uibDef.MinHeight = minHeight;
        uibDef.MaxHeight = maxHeight;
        uibDef.HorizontalAlignment = GetHorizontalAlignment(horizontalAlignment);
        uibDef.VerticalAlignment = GetVerticalAlignment(verticalAlignment);
        uibDef.WantsOnChange = wantsOnChange;
        uibDef.DisplayFilter = displayFilter;

        if (initialValue == InitialDropDownValue)
        {
            uibDef.AddDropDownOption(InitialDropDownValue);
        }
        foreach (string sOption in dropDownOptions)
        {
            uibDef.AddDropDownOption(sOption);
        }
        if (!string.IsNullOrEmpty(margin))
        {
            uibDef.Margin = margin;
        }

        uib.AppendBlock(uibDef);
    }
    public static void AddDropDown(this UIBuilder uib, string destVar, string initialValue, List<string[]> dropDownOptions, uint row, uint column, uint rowSpan = 1, uint columnSpan = 1, int width = -1, int minWidth = -1, int maxWidth = -1, int height = -1, int minHeight = -1, int maxHeight = -1, UIBlockHorizontalAlignment horizontalAlignment = UIBlockHorizontalAlignment.Left, UIBlockVerticalAlignment verticalAlignment = UIBlockVerticalAlignment.Center, string margin = "", bool wantsOnChange = false)
    {
        UIBlockDefinition uibDef = new UIBlockDefinition();
        uibDef.Type = UIBlockType.DropDown;
        uibDef.DestVar = destVar;
        uibDef.InitialValue = initialValue;
        uibDef.Row = (int)row;
        uibDef.RowSpan = (int)rowSpan;
        uibDef.Column = (int)column;
        uibDef.ColumnSpan = (int)columnSpan;
        uibDef.Width = width;
        uibDef.MinWidth = minWidth;
        uibDef.MaxWidth = maxWidth;
        uibDef.Height = height;
        uibDef.MinHeight = minHeight;
        uibDef.MaxHeight = maxHeight;
        uibDef.HorizontalAlignment = GetHorizontalAlignment(horizontalAlignment);
        uibDef.VerticalAlignment = GetVerticalAlignment(verticalAlignment);
        uibDef.WantsOnChange = wantsOnChange;

        foreach (string[] asOption in dropDownOptions)
        {
            uibDef.AddDropDownOption(asOption[0], asOption[1]);
        }
        if (!string.IsNullOrEmpty(margin))
        {
            uibDef.Margin = margin;
        }

        uib.AppendBlock(uibDef);
    }

    public static void AddButton(this UIBuilder uib, string text, string destVar, uint row, uint column, uint width, uint height, uint rowSpan = 1, uint columnSpan = 1, UIBlockHorizontalAlignment horizontalAlignment = UIBlockHorizontalAlignment.Left, UIBlockVerticalAlignment verticalAlignment = UIBlockVerticalAlignment.Center, string margin = "")
    {
        UIBlockDefinition uibDef = new UIBlockDefinition();
        uibDef.Type = UIBlockType.Button;
        uibDef.Text = text;
        uibDef.DestVar = destVar;
        uibDef.Row = (int)row;
        uibDef.RowSpan = (int)rowSpan;
        uibDef.Column = (int)column;
        uibDef.ColumnSpan = (int)columnSpan;
        uibDef.Width = (int)width;
        uibDef.Height = (int)height;
        uibDef.HorizontalAlignment = GetHorizontalAlignment(horizontalAlignment);
        uibDef.VerticalAlignment = GetVerticalAlignment(verticalAlignment);

        if (!string.IsNullOrEmpty(margin))
        {
            uibDef.Margin = margin;
        }

        uib.AppendBlock(uibDef);
    }
    #endregion

    #region Private Methods
    private static string GetStyle(UIBlockStyle style)
    {
        switch (style)
        {
            case UIBlockStyle.Title1: return "Title1";
            case UIBlockStyle.Title2: return "Title2";
            case UIBlockStyle.Title3: return "Title3";
            default: return "Title3";
        }
    }
    private static string GetHorizontalAlignment(UIBlockHorizontalAlignment horizontalAlignment)
    {
        switch (horizontalAlignment)
        {
            case UIBlockHorizontalAlignment.Left: return "Left";
            case UIBlockHorizontalAlignment.Center: return "Center";
            case UIBlockHorizontalAlignment.Right: return "Right";
            default: return "Left";
        }
    }
    private static string GetVerticalAlignment(UIBlockVerticalAlignment verticalAlignment)
    {
        switch (verticalAlignment)
        {
            case UIBlockVerticalAlignment.Top: return "Top";
            case UIBlockVerticalAlignment.Center: return "Center";
            case UIBlockVerticalAlignment.Bottom: return "Bottom";
            default: return "Center";
        }
    }
    #endregion
}
Curtis Baiden [DevOps Advocate] Selected answer as best 16th November 2023
Curtis Baiden [DevOps Advocate] commented 3rd October 2023

Hello Matthias, thank you for your code example, it really helps. I have one question: For my script I want to select a value but only make changes after a button is clicked, I don’t want the change to happen straight away. Do I have to set the WantsOnChange param to false, and if I do that I am not sure how to use UIResult to get the selected value.

Matthias Declerck [SLC] [DevOps Advocate] commented 3rd October 2023

Hi Curtis, UIresult will work as the same.
When you press the button, all loaded destination variables will fill in their correspondent value. So the one of your dropdown will be the selected value.
that collection of variables will be passed from client to server, which then will be parsed into sort of dictionary. The UIresult will then look up by variable name. You can always try and experiment, for example duplicate the script and figure it out ☺ Hope this helps you further.

Curtis Baiden [DevOps Advocate] commented 6th October 2023

I have managed to make it work after all your with a bit of experimenting, thank you

Matthias Declerck [SLC] [DevOps Advocate] commented 6th October 2023

Curtis, that’s great to hear! Hopefully you gained bit of experience as well 🙂 In order to finish up this post thread, could you mark this answer as Best answer? Just simply select the check marker on the top left corner of this answer. Thanks in advance and have a nice day further.

You are viewing 1 out of 3 answers, click here to view all answers.
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin