BookmarkSubscribeRSS Feed
ShenQicheng
Obsidian | Level 7

Hi,

I am creating an EG custom task with more than one input data and [InputRequired] attribute being set to [InputResourceType.None].

In task’s [Show] override method I use the [Consumer.ShowInputDataSelector] to require all input data before showing task form.

There is a [TaskSelectedDataControl] control on the task form that user can use it to filter the dataset.

Here is the problem:

  1. Create a new task on a new EG project.
  2. Select a dataset for input data in the pop-up dialog.
  3. Click the [Edit] button of [TaskSelectedDataControl] control on the task form.
  4. Click the [OK] button of the filter setting dialog.

      

An error occurred say “Can not select a data source. Reason: Index out of range.”.

   

If I ignore the above error and save the task, (the selected input data comes out to the project flow at this time) and open it again and do same processes as above, no error occurs.

   

Is there any way that I can resolve this problem?

Is there any must thing that I missed after calling ShowInputDataSelector?

   

You can reproduce this by making a few changes on SASPress.Examples.RunningTotals:

  1. Task attribute: [InputRequired(InputResourceType.None)]
  2. At beginning of public override ShowResult Show(System.Windows.Forms.IWin32Window Owner) insert following code  

            var cookie = string.Empty;

            var selectedDatasets = Consumer.ShowInputDataSelector(

                null, DataSelectionMode.ReadOnlySingleInput, ServerAccessMode.AnyServer,

                "", "SASHELP", string.Empty, ref cookie) as ISASTaskData2[];

            Consumer.ClearInputData();

            Consumer.AddInputData(selectedDatasets[0]);   


Thanks in advance.

2 REPLIES 2
ChrisHemedinger
Community Manager

Hi,

Be sure to check for null on the selectedDatasets variable before you try to reference it.  If you click Cancel on the data selector, the return will be null. You should then call ClearInputData and AddInputData only if the selectedDatasets != null.

Also, ShowInputDataSelector returns an array of ISASTaskData[], not ISASTaskData2[].  You should probably not try to cast this to ISASTaskData2   The returned object in the array will support ISASTaskData and ISASTaskData2, but the way the interfaces are designed, I would not cast those to other types unless you need the specific ISASTaskData2 methods/properties.

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
ShenQicheng
Obsidian | Level 7

Hi,

Thanks for you answer, but it still not make my problem solved.

Sorry for the incomplete sample code I posted.

Yes, I do confirm the selectedDatasets variable being not null before doing anything further in my real code.

The reason that I cast the return type of ShowInputDataSelector methods to ISASTaskData2[] is for convenience that I will need this later:

1. Get columns of the dataset by using GetColumns() methods of SasData class whose constructor needs a SASTaskData2 type parameter.

2. Set the TaskData property of TaskSelectedDataControl.

I can change both of them to do cast right at it is being used , if it helps, just like the SASPress.Examples.RunningTotals sample shows.

My prolem is, I call Consumer.ShowInputDataSelector to select a data and set it to TaskSelectedDataControl's TaskData property, then in the TaskSelectedDataControl I do nothing but click the OK button, the error message box pops up.

This only occures when I create the task on a new project.

Thanks

Shen

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1435 views
  • 0 likes
  • 2 in conversation