none
Problem with radio button selection on FIM Custom activity UI RRS feed

  • Question

  • Hi,

     I have developed a new custom activity for FIM and deployed it. In the activity UI, we provide three radio buttons to select different options. The activity UI looks like below:

    For Option 1 selection, the activity receives the string Option 1 and so on for other options. Based on that value, we run different business logic in the activity. However, I am facing issues when I select Options 2 and 3. When I select Option 2 or 3, it gets selected and the value received in the activity during execution is also proper. However, when I open the workflow to check what Option we have selected, then the UI always displays "Option 1" though it is sending values for Option 2 and 3 as expected during execution.

    Below is the UI code for the activity:

    public static DependencyProperty ActivityNameProperty = DependencyProperty.Register("ActivityName", typeof(System.String), typeof(CustomActivity));
    [Description("Please specify the target attribute")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [Browsable(true)]
    public string ActivityName
    {
        get
        {
            return ((String)(base.GetValue(CustomActivity.ActivityNameProperty)));
        }
        set
        {
            base.SetValue(CustomActivity.ActivityNameProperty, value);
        }
    }
    
     static string[] ActivityNames = new string[]
    { 
        "Option1", 
        "Option2", 
        "Option3"
    };
    
    public class CustomActivitySettingsPart : ActivitySettingsPart
    {
    
       public override Activity GenerateActivityOnWorkflow(SequentialWorkflow workflow)
       {
           if (!this.ValidateInputs())
           {
               return null;
           }
           CustomActivity changeActivity = new CustomActivity();
           changeActivity.ActivityName = this.GetRadioSelection("activityToRun");
           return changeActivity;
       }
    
       public override void LoadActivitySettings(System.Workflow.ComponentModel.Activity activity)
       {
           CustomActivity changeActivity = activity as CustomActivity;
           if (changeActivity != null)
           {
               this.SetRadioSelection("activityToRun", changeActivity.ActivityName);
           }
       }
    
       public override ActivitySettingsPartData PersistSettings()
       {
           ActivitySettingsPartData data = new ActivitySettingsPartData();
           data["ActivityName"] = this.GetRadioSelection("activityToRun");
           return data;
       }
    
       public override void RestoreSettings(ActivitySettingsPartData data)
       {
           if (data != null)
           {
               this.SetRadioSelection("activityToRun", (string)(data["ActivityName"]));
           }
    
       }
    
       public override void SwitchMode(ActivitySettingsPartMode mode)
       {
           bool readOnly = (mode == ActivitySettingsPartMode.View);
           this.SetRadioListReadOnlyOption("activityToRun", readOnly);
       }
    
       public override string Title
       {
           get { return "My custom activity"; }
       }
    
       public override bool ValidateInputs()
       {
           return true;
       }
    
       /// <summary>
       ///  Creates a Table that contains the controls used by the activity UI
       ///  in the Workflow Designer of the FIM portal. Adds that Table to the
       ///  collection of Controls that defines each activity that can be selected
       ///  in the Workflow Designer of the FIM Portal. Calls the base class of 
       ///  ActivitySettingsPart to render the controls in the UI.
       /// </summary>
       protected override void CreateChildControls()
       {
           Table controlLayoutTable;
           controlLayoutTable = new Table();
    
           //Width is set to 100% of the control size
           controlLayoutTable.Width = Unit.Percentage(100.0);
           controlLayoutTable.BorderWidth = 0;
           controlLayoutTable.CellPadding = 2;
    
           controlLayoutTable.Rows.Add(this.AddTableRowRadioList("Please select one option", "activityToRun", ActivityNames, ActivityNames[0]));
           this.Controls.Add(controlLayoutTable);
    
           base.CreateChildControls();
       }
    
       #region "Radio Functions"
       private TableRow AddTableRowRadioList(String labelText, String controlID, String[] radioOptions, String defaultValue)
       {
           TableRow row = new TableRow();
           TableCell labelCell = new TableCell();
           TableCell controlCell = new TableCell();
           Label label = new Label();
           RadioButtonList radioList = new RadioButtonList();
    
           label.Text = labelText;
           label.CssClass = base.LabelCssClass;
           labelCell.Controls.Add(label);
           radioList.ID = controlID;
           foreach (String Item in radioOptions)
           {
               radioList.Items.Add(new ListItem(Item, Item));
           }
           radioList.SelectedValue = defaultValue;
           radioList.RepeatDirection = RepeatDirection.Vertical;
           controlCell.Controls.Add(radioList);
           row.Cells.Add(labelCell);
           row.Cells.Add(controlCell);
           return row;
       }
    
       private String GetRadioSelection(String radioListID)
       {
           RadioButtonList radioList = (RadioButtonList)this.FindControl(radioListID);
           return radioList.SelectedValue;
       }
       private void SetRadioSelection(String radioListID, String radioSelection)
       {
           RadioButtonList radioList = (RadioButtonList)this.FindControl(radioListID);
           if (radioList != null)
           {
               radioList.SelectedValue = radioSelection;
           }
           else
           {
               radioList.SelectedValue = radioList.Items[0].Text;
           }
       }
    
       private void SetRadioListReadOnlyOption(String radioListID, bool readOnly)
       {
           RadioButtonList radioList = (RadioButtonList)this.FindControl(radioListID);
           radioList.Enabled = !readOnly;
       }
       #endregion
    }

    Please let know if I have missed anything in the UI code. When the activity reloads, it is always displaying first option as selected.


    • Edited by vmnn Monday, August 8, 2016 8:46 AM spell error
    Sunday, August 7, 2016 3:28 PM