Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Programmatically set a field value of all selected rows by an action

I need to create an action that allows the user to set a field value of all selected (or visible) rows in the grid. For example "Set the field "payed" to true on each selected row".
Any suggestion?

Thanks!
1 person has
this question
+1
Reply
  • You will have to create a business rule. In that rule you will need to use the Arguments object and SelectedValues property. Then you can iterate through each item and change the values you want.

    Perhaps something like this...

    For Each payed in Arguments.SelectedValues
    ..your code to do something

    Next
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • If it's always going to be the same field that is changing, for example the field that you mention, and its always going to be set to the same value, then you could create a custom sql action that is set to be visible when row(s) have been selected. I have a table where the users can select whatever rows that they want and then all of the selected records have their "archive" field set to 1 (true). My code to that is:

    UPDATE dbo.tblParents SET ARCHIVED = 1 WHERE [PREF] = @Pref;

    If you want the users to select the field that you want updating and to enter the value then you probably need to create a controller first, that contains a list of the fields that they can select plus an entry field. You can still use an sql action but use the parameters from the controller that you've created. Personally I find that if it's just a bulk update to a table that's required then the sql action is the easiest way to go.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • In the code snippet I offered, I create sql parameters to the hold the values I want. Using code to create SQL parameters and then to populate the parameters with the values I want. I have several parameters for each row. Then I pass the parameters to the stored proc in an ExecuteNonQuery. I execute the stored proc for each row, but its so fast there is not a noticeable performance hit.

    My problem is I have calculated values so they are not the same for each row selected and updated.

    So its kind of marriage with what Peter is describing.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • I agree with you there John, I do something similar when I have a lot of updates to do and find it easy to do using stored procedures called from a business rule passing parameters as required. I've said it before a few times, there's a lot of our work that can be done on the database itself, with limited code to do in COT.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated