Set Expression Box value from Script Function - InfoPath Dev
in

InfoPath Dev

Set Expression Box value from Script Function

Last post 08-30-2005 05:24 AM by vt_asparagus. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-29-2005 07:01 PM

    Set Expression Box value from Script Function

    I have a two fold InfoPath question that is somewhat related based on some of my research.

    1 – Has anyone had success with setting a value into an Expression Box from a script or .NET managed code function? Preferably script but it should not matter.
    2 – Has anyone had success with dynamically loading the options into a combo box?

    The expression box is an interesting question. When working with InfoPath, whenever you add a control to your form, a new element will be added to your XSD. In this situation lets say you have roll up values you would like to display but you do not want to create a new element in your XSD because the value can be calculated. This would lead down the path of wanting to use an expression box. An expression box works well if you are doing some totaling but lets say that roll up would display a word that is contextual based upon the state data in the form. So the next step would be to say, can I call a function in script or .NET managed code that would return a string that would be set into an expression box. I have been able to successfully create methods in script that will return a bool that can be used with conditional formatting as an XPath expression (ex. xdExtension:IsUserValid()). Although, I have not been successful with creating an expression box that will have its value set from a script method.

    I have read some message boards that discussed going into the manifest of the InfoPath form and adding a Preserve Code block to achieve this result. Unfortunately, I have not had much luck implementing it. As well, from a client perspective this can be viewed as a hack and a maintenance issue that would have to be managed.

    Does anyone have an alternative solution?
    Jason
    http://www.k2distillery.com/
  • 08-29-2005 09:58 PM In reply to

    Re: Set Expression Box value from Script Function

    Hi VT Asparagus,
    1. just bind the expression box to a field in your main data source or secondary data source and set the value of that in code (or wherever). Then the expression box will change whenever hte value changes.
    2. same thing - just bind to a secondary data source and update this automatically on the fly.

    When will you need to dynamically load the values?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 08-30-2005 05:24 AM In reply to

    Re: Set Expression Box value from Script Function

    I think I understand what you are saying. But I do not want to add another element to my schema for binding to the expression box solely for printing a value. Think of an enumeration. I have an element named Status which is an int type (1,2,3,4). Sometimes the print value (Select..., Approve, Deny, Change). In other places I want to print (No Action, Approved, Denied, Changed) or (No Action, Changed, Denied). It is contextual to the state of the form.

    So, if I did what you are suggesting, I would bind the Expression Box to the Status field in my main data source. But the problem is the expression box would print an int, not a string? Another option would force me to create another element (a Status Display element) in my main schema which would be set when the Status element changes. Problem is I really did not want to have to add an element that would have to be passed around in my InfoPath workflow just so I can print a value. I believe that is what you are suggesting, if that is my only option, I will sallow the medicine. Do not want to give the perception that I have to add elements and data into my main data source to enable the InfoPath GUI to display calculated values.

    I am trying to find a paradigm in InfoPath which is similar to a label control in .NET Winforms.

    To answer your question, the values would be dynamically loaded when the status changes. So I would use the AfterChange event since the other events lock the DOM. Plus I would like to only print the status if the value was committed to the DOM.
    Jason
    http://www.k2distillery.com/
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.