Call code from a rule...? - InfoPath Dev
in

InfoPath Dev

Call code from a rule...?

Last post 02-19-2006 11:11 PM by nukkumatti. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 02-07-2006 05:46 AM

    Call code from a rule...?

    Hello,

    I´m new to infopath and actually I´m developing my first dynamic form in infopath.
    Now I want to call a function (Jscript) from a rule but I haven´t found a rules action type "Call code" or something similar.

    Isn´t it possible to call code/script from a rule?

    I appreciate any help.

    Karsten
    Karsten
  • 02-07-2006 09:46 AM In reply to

    Re: Call code from a rule...?

    I have tried in the past I was not able to, but someone please correct me if I am wrong because I would love to be able to do that too.

    I was able to call code to do conditional formatting (search on xdExtension for more information).
    Jason
    http://www.k2distillery.com/
  • 02-07-2006 09:48 AM In reply to

    Re: Call code from a rule...?

    Hi Karsten and welcome to our forum!

    What is your rule attached to? If it is a button, then you can just attached the code to the button and it will be executed when the button is clicked. Otherwise, you might want to look at the OnBeforeChange() and OnAfterChange() events - maybe you can attach your code to one of these events of the control that you are running rules on.

    Could you provide a little more information please? Like what is the rule doing? What is the code doing? Why can't you combine the two?

    I hope this helps!

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-07-2006 10:28 AM In reply to

    Re: Call code from a rule...?

    Hello,

    ... in my special case I want to switch between different views after selected these views in a drop-down list. I wonder that I have the opportunity to call a rule action type "switch view" if I use a command button but I don´t have the same rule action type by using a drop-down list. In my opinion this is a little bit curious... ;-)
    Furthermore I can´t see that I can attach any code to the events (Are there any?) of a drop-down list.

    What I would like to do at least is to switch between different views immediately after the selection of them in a drop-down list without additionally press a command button.

    Thanks for all your help.

    Karsten
    Karsten
  • 02-07-2006 11:15 AM In reply to

    Re: Call code from a rule...?

    Yes, you can do this. Attach the following code to the OnAfterChange event of the drop-down list:

    XDocument.View.SwitchView( e.Site.text );

    To generate the event function, find the node that the drop-down list is bound to in the Data Source task pane, Double-click it, choose Data Validation and Event Handlers, select OnAfterChange, and then click Edit.

    Depending on how you have your form set up, the Microsoft Script Editor or Visual Studio should open with a freshly generated function that will be executed whenever the value of your drop-down list changes.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-07-2006 11:18 AM In reply to

    Re: Call code from a rule...?

    Jason, check out this page:http://blogs.msdn.com/infopath/archive/2005/06/17/430347.aspx

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-07-2006 02:39 PM In reply to

    Re: Call code from a rule...?

    Hello Matt,

    thank you for your tip regarding the "OnAfterChange" event which I haven´t knew by now but unfortunately I got the following error after I changed my selection in the drop-down list:

    "Invalid context for OM call Infopath"

    Do you know how I can avoid this error.

    Thanks for your help

    Karsten
    Karsten
  • 02-07-2006 03:36 PM In reply to

    Re: Call code from a rule...?

    Thanks Matt...with a little trickery you can do anything...J
    Jason
    http://www.k2distillery.com/
  • 02-17-2006 04:05 PM In reply to

    Re: Call code from a rule...?

    After doing some investigation I don't think it's possible to change the view upon changing the value of a drop-down list. I think the best you will be able to do is display all of the views in a drop-down list, and a GO button next to the drop-down. The user can select the view from the drop-down list and then click the GO button the switch to that view.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-19-2006 11:11 PM In reply to

    Re: Call code from a rule...?

    Hi I could also think about another solution haven't tried it an am not sure if it works though.

    For your drop downlist use "Look up values in a data connection, webservice, file or sharepoint library or list" for the Listbox entries. At first you need to create an XML file as your datasource with the listbox entries you require. That is quite easy with Infopath. Check out this thread to get what I mean: (thx to MFaus again)http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1258
    .
    Then put a textbox into your form (can also be a hidden one) and use code like this in the OnAfterChange of the DDL to put the selected "text/view" string into the textbox:
    #region DropDownList event Handlers/ write selected string into textboxes
    // The following function handler is created by Microsoft Office InfoPath. Do not
    // modify the type or number of arguments.
    [InfoPathEventHandler(MatchPath="/my:myFields/my:secMainSection/my:ddlRegion", EventType=InfoPathEventType.OnAfterChange)]
    public void ddlRegion_OnAfterChange(DataDOMEvent e)
    {
    // Write code here to restore the global state.


    if (e.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond
    // to the changes.
    string val = e.Source.text;
    IXMLDOMNode nodeRegion = thisXDocument.DOM.selectSingleNode("my:myFields/my:tbHiddenRegions");
    nodeRegion.text = val;
    }
    .

    Then in the OnAfterChangeEvent of the textbox use the earlier mentioned SwitchView method maybe with some "if/or switch case" help to check what string is in the textbox. Hope this is understandable a least a bit.
    May be Matt can confirm wether or not it is possible like this.
    Good luck.

    Listen to Motörhead cos they play Rock'n Roll :)
    Listen to Motörhead cos they play Rock'n Roll :)
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.