How to make rules fire no matter what field is modified - InfoPath Dev
in

InfoPath Dev

How to make rules fire no matter what field is modified

Last post 10-23-2008 06:19 AM by santhoshp. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-20-2008 08:03 AM

    How to make rules fire no matter what field is modified

    If I have 3 fields that should trigger a rule to fire.  How do I make the rule fire without having to put the rule in each field.  I have 10 rules times 3 fields is 30 rules.  I would prefer to put the 10 rules in one spot.  I tested putting it in at the group level but the rule would not fire. Thanks, Randy

     

  • 10-20-2008 10:31 PM In reply to

    Re: How to make rules fire no matter what field is modified

    Hi,

    If the 3 fields are in the same section then apply OnAfterChange functionality to the section and implement all your rules in that OnAfterChange functionality. For example please follow the below code.

    [InfoPathEventHandler(MatchPath = "/my:myFields/my:group1", EventType = InfoPathEventType.OnAfterChange)]
            public void group1_OnAfterChange(DataDOMEvent e)
    {

               if (e.IsUndoRedo)
                {
                    return;
                }
     if( e.Site.baseName == "field1" || e.Site.baseName == "field2" || e.Site.baseName == "field3")
     {
      //implement your rules here.
     }
    }


    if the 3 fields are in the different sections then implment the below code in formcode.cs


    [InfoPathEventHandler(MatchPath = "/my:myFields/my:field1 |/my:myFields/my:field2 |/my:myFields/my:field3", EventType = InfoPathEventType.OnAfterChange)]
            public void group1_OnAfterChange(DataDOMEvent e)
    {

               if (e.IsUndoRedo)
                {
                    return;
                }
      //implement your rules here.
    }

     

     

     

    Chandrakanth/GGKTech
  • 10-21-2008 07:01 AM In reply to

    Re: How to make rules fire no matter what field is modified

    Thanks,

    I have one question.  Can you include a sample rule.  I am not sure how to translate my rules into code.

  • 10-22-2008 12:01 AM In reply to

    Re: How to make rules fire no matter what field is modified

    Hi,

    For example if your rule is "When user checks the field1 check box then you need to set some value to the field2 text box field".

    For above thing you need to write the code in field1 OnAfterChange like this.

     [InfoPathEventHandler(MatchPath = "/my:myFields/my:field1", EventType = InfoPathEventType.OnAfterChange)]

            Public void field1_OnAfterChange (DataDOMEvent e)

            {

                // Write your code here to restore the global state.

                If (e.IsUndoRedo)

                {

                    // An undo or redo operation has occurred and the DOM is read-only.

                    return;

                }           

                if (e.Site.text == "True")

                {

                    thisXDocument.DOM.selectSingleNode ("/my: myFields/my: field2").text = "Sample App";

                }         

            }

    Like this you can set all your rules in the code itself.

    Chandrakanth/GGKTech
  • 10-23-2008 06:19 AM In reply to

    Re: How to make rules fire no matter what field is modified

    Hi, 

    You can do this without using code.


       1. Open the manifest.xsf file in editor. Search for the rule name. Then you will find ‘rule’ node.
          <xsf:rule caption="Rule Name" isEnabled="yes">

       2. Above this node you will have ‘ruleSet’ node.
          <xsf:ruleSet name="ruleSet_1">

       3. Search for the rule set name (e.g. ruleSet_1). Then you will find ‘ruleSetAction’ node. Above that node you will find ‘domEventHandler’ node.
          <xsf:domEventHandler match="/my:myFields/my:field1 ">

       4. Here you can add the fields on which you want to apply the same rule by putting or (|) between the fields Xpath.
         <xsf:domEventHandler match="/my:myFields/my:field1|/my:myFields/my:field2|/my:myFields/my:field3">


    This will work. But editing the manifest.xsf file is not recommended.

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.