(how) can qrules and Custom Code coexist at the same time - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

(how) can qrules and Custom Code coexist at the same time

Last post 10-19-2010 06:28 PM by joanfuture. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-15-2010 03:14 AM

    (how) can qrules and Custom Code coexist at the same time

    I use qrules. Now I have something, that I probably need to code. In qrules Version 2.2 you write, that it can coexist with customcode (I use c#).

    However I don't bring qrules to work once I have created the custom code project.I tried reinjecting it, but it won't work until I remove the customcode project and reinject qrules.

    How exactly does the procedure work to habe both, qrules and customcode?

    Thanks

    Filed under: , ,
  • 10-15-2010 04:52 AM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Here's a document that explains how to use qRules along with custom code:

    http://www.infopathdev.com/files/folders/qrules/entry56111.aspx

    Note that this will only work with InfoPath 2007 OM (C# or VB) code.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-19-2010 05:34 AM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Hello Jimmy,

    thank you very much for your Reply. I have it 99% working now. The User guide misses one thing though you might want to add or maybe I was too quick. It asks me to add the .dll-File, that I didn't just have lying around of course. I extracted it from the xsn-file that I once injected qrules in. But then again, at this level, users/programmers might know this extracing stuff, But I thought I mention it.

    Do you know, if ALL features will be supported in this environment? I can get the Setcaption-Command to work, however the "SetSave /saveasfile=superman.xml" would not work. I have no idea why. I thought I checked on injecting the file into the form, but then again, i did'nt inject it, did I?   So I guess at some place you differ between the webbrowser-compatible -DLL and the client-DLL. Is there a way I can double check the setSave-Feature? Currently I am working with a client compatible qrules installation, I thought.

    Best regards Michael

  • 10-19-2010 05:53 AM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Hello again, and thank you for your feedback,

    I believe the qRules DLL should be present in the qRules installation folder and not require any extraction from an XSN.  The tutorial does instruct the reader to navigate to the qRules installation folder when adding the DLL to the Visual Studio project, so I think we have that point covered.  Please let me know if that is not the case or if there is a way that you think would make it clearer.

    The SetSave and SetCaption commands were added after that tutorial was written, and respectively require directing the form's Save and ContextChanged events to qRules, with events like this:

    public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
    {
         qRulesMain.ContextChanged(
    this, Application, e);
    }

    public void FormEvents_Save(object sender, SaveEventArgs e)
    {
         qRulesMain.FormSave(
    this, Application, e);
    }

    I will make a note for us to update the documentation.  Please let me know if you can't figure this step out.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-19-2010 06:51 AM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Hello,

    oops, you are right of course, I misinterpreted the "installation folder" with my projectfolder, where of couse the file was not. Everything is fine, and you do, as I suspected have two files, one for browser and one for client. Thanks.

    And oh my god, I got the other comands to work as well eventually. Here is what is also important for anyone else, that is not too familiar with coding:
    At first I just copied the above methods Jimmy put and they are correct, however my form didn't jump into those methods, because the following two lines were missing in the method "InternalStartup()", I guess they are called EventHandler. One can generate these two lines by selecting the ContextChanged-Event and the Save-Event in InfoPath.

    public void InternalStartup()
    {
    ...
    EventManager.FormEvents.Save += new SaveEventHandler(FormEvents_Save);
    EventManager.FormEvents.ContextChanged +=
    new ContextChangedEventHandler(FormEvents_ContextChanged);
    }

    Also these two following methods are generated, into which I then copied Jimmy's statements, so it looks like this:
    public void FormEvents_Save(object sender, SaveEventArgs e)

    {

    // Write your code that will run before a Save or Save As operation here.

    qRulesMain.FormSave(this, Application, e);

    // The Dirty property will be set to false if save is successful.

    e.PerformSaveOperation();

    // Write your code that will run after saving here.

    e.CancelableArgs.Cancel = false;

    }

    public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)

    {

    if (e.ChangeType == "ContextNode")

    {

    // The XML selection or context has changed.

    // Write your code here.

    qRulesMain.ContextChanged(this, Application, e);return;

    }

    }

    As far as I can tell, this thing is working just marvelous.
    Thanks again for your great and quick help.
    By the way, how did you quote your code-example, so it looks so nice?

    best regards Michael

  • 10-19-2010 09:58 AM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Glad to hear you figured it out.  I suggest you remove these lines from your Save event:

    e.PerformSaveOperation();
    // Write your code that will run after saving here.
    e.CancelableArgs.Cancel = false;

    The qRules FormSave() method fully manages the save operation and the CancelableArgs, and having those lines could result in the form being saved twice, or saved when you want to prevent it from being saved.

    To cleanly indent text on this forum, just use the indent button  available when you're entering a message.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-19-2010 06:28 PM In reply to

    Re: (how) can qrules and Custom Code coexist at the same time

    Thank you, I will do that.
    Best regards
    Michael

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