removing xml attachment when i email a form - InfoPath Dev
in

InfoPath Dev

removing xml attachment when i email a form

Last post 04-30-2008 07:27 AM by Clay Fox. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 04-11-2008 06:31 PM

    removing xml attachment when i email a form

    Hello,

      I have recently created a form with a send to email button. I am using infopath 2003 what we would like to do is have the ability to remove the attachment prior to sending out the email as we want the end user only to be able to view what is in the body of the email and not be able to manipulate the xml file.

     

    Thanks,

    Jarret

  • 04-12-2008 06:59 AM In reply to

    Re: removing xml attachment when i email a form

    Hi Jarret, Welcome to the forum.

    Ussually, you would just hide the attachment control.

    Create a field called readonly that is a boolean.

    When you sumit to email set it to true.

    Put conditional formatting on the attachment control or the section it resides within to hide if Readonly is true.

    You also could maybe set the field value of the attachment to blank or create a different view readonly users saw.

    Best Practice:

    I use an Active Directory webservice to identify each person who opens the form and then use their group membership to decide what access or privileges they have within the form.

  • 04-14-2008 10:28 AM In reply to

    Re: removing xml attachment when i email a form

    Clay,

    How do I set the field value of the attachment to blank or make the form readonly. I have attached the code for your review. Thanks,Jarret 

    Here is the code:

    ============================================================================================

     

    /*

     * This file contains functions for data validation and form-level events.

     * Because the functions are referenced in the form definition (.xsf) file,

     * it is recommended that you do not modify the name of the function,

     * or the name and number of arguments.

     *

    */

     

    // The following line is created by Microsoft Office InfoPath to define the prefixes

    // for all the known namespaces in the main XML data file.

    // Any modification to the form files made outside of InfoPath

    // will not be automatically updated.

    //<namespacesDefinition>

    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD" xmlns:iss="http://schemas.microsoft.com/office/infopath/2003/sample/IssueTracking"');

    //</namespacesDefinition>

     

    function XDocument::OnLoad(event)

    {

          // Avoid DOM updates when the document has been digitally signed.

          if (XDocument.IsSigned)

                return;

     

          // Initialize the date

          initializeNodeValue("/iss:issue/iss:createdDate", getDateString()+"T"+getTimeString());

    }

     

    //=======

    // The following function handler is created by Microsoft Office InfoPath.

    // Do not modify the name of the function, or the name and number of arguments.

    //=======

    function CTRL19_5::OnClick(eventObj)

    {

          // Write your code here

    }

     

    //=======

    // The following function handler is created by Microsoft Office InfoPath.

    // Do not modify the name of the function, or the name and number of arguments.

    //=======

    /*

    function SendEmailBtn::OnClick(eventObj)

    {

          // Write your code here

    }

    */

     

    /*------------------------------------------------------------------------------

          This function handler is generated and managed automatically.

          Do not rename the function or alter its parameter list.

    ------------------------------------------------------------------------------*/

    function SendEmailBtn::OnClick(oEvent)

    {

          createEmail();

    }

     

     

     

    function createEmail()

    {

          var xmlContributors = XDocument.DOM.selectNodes("/iss:issue/iss:contributors/iss:contributor");

          var xmlContributor;

          var xmlTitle = XDocument.DOM.selectSingleNode("/iss:issue/iss:title");

          var rgRecipients = new Array();

     

          while (xmlContributor = xmlContributors.nextNode())

                rgRecipients.push(getNodeValue(xmlContributor.selectSingleNode("iss:emailAddressPrimary")));

     

          try

                {

                var oEnvelope = XDocument.View.Window.MailEnvelope;

     

                oEnvelope.To = rgRecipients.join("; ");

                oEnvelope.Subject = getNodeValue(xmlTitle);

                oEnvelope.Visible = true;

                }

          catch (ex)

                {

                XDocument.UI.Alert(ex.description);

                }

    }

     

    /*------------------------------------------------------------------------------

     

          Common form template functions section - the following code is common to all out-of-box form templates.

     

    ------------------------------------------------------------------------------*/

     

    /* =============================================================================

          Currency handling

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          updateCurrency()

    ------------------------------------------------------------------------------*/

    function updateCurrency(xmlNode, strPrefix)

    {

          var xmlName = xmlNode.selectSingleNode(strPrefix + 'name');

          var xmlSymbol = xmlNode.selectSingleNode(strPrefix + 'symbol');

     

          var strName = xmlName.text;

          var strSymbol = lookupCurrencySymbol(strName);

     

          if (strSymbol)

          {

                setNodeValue(xmlSymbol, '(' + strSymbol + ') ');

          }

          else

          {

                setNodeValue(xmlName, '');

                setNodeValue(xmlSymbol, '');

          }

    }

     

    /*------------------------------------------------------------------------------

          lookupCurrencySymbol()

    ------------------------------------------------------------------------------*/

    function lookupCurrencySymbol(strName)

    {

          var xmlCurDom = XDocument.GetDOM("currencies");

          var xmlCurrency = xmlCurDom.selectSingleNode("/currencies/currency[@name = '" + strName + "']");

     

          if (xmlCurrency)

                return xmlCurrency.getAttribute("symbol");

    }

     

    /* =============================================================================

          Date/Time handling

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          getDateString()

    ------------------------------------------------------------------------------*/

    function getDateString(oDate)

    {

          // Use today as default value.

          if (oDate == null)

                oDate = new Date();

     

          var m = oDate.getMonth() + 1;

          var d = oDate.getDate();

     

          if (m < 10)

                m = "0" + m;

     

          if (d < 10)

                d = "0" + d;

     

          // ISO 8601 date (YYYY-MM-DD).

          return oDate.getFullYear() + "-" + m + "-" + d;

    }

     

    /*------------------------------------------------------------------------------

          getTimeString()

    ------------------------------------------------------------------------------*/

    function getTimeString(oTime)

    {

          // Use now as default value.

          if (oTime == null)

                oTime = new Date();

     

          var h = oTime.getHours();

          var m = oTime.getMinutes();

          var s = oTime.getSeconds();

          var ms = oTime.getMilliseconds();

     

          if (h < 10)

                h = "0" + h;

     

          if (m < 10)

                m = "0" + m;

     

          if (s < 10)

                s = "0" + s;

     

          if (ms < 100)

                ms = "0" + (ms < 10 ? "0" : "") + ms;

     

          // ISO 8601 time (HH:MM:SS.SSS).

          return h + ":" + m + ":" + s + "." + ms;

    }

    /* =============================================================================

          Language conversion operations     

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          convertXMLNumberToJScript()

    ------------------------------------------------------------------------------*/

    function convertXMLNumberToJScript(value)

    {

          var retVal;

     

          switch (value)

          {

                case "-INF":

                      retVal = Number.NEGATIVE_INFINITY;

                      break;

     

                case "INF":

                      retVal = Number.POSITIVE_INFINITY;

                      break;

     

                case "NaN":

                      retVal = NaN;

                      break;

     

                default:

                      //If no prefix of its argument can be parsed as a

                      //float, parseFloat will return NaN. Otherwise, it

                      //will return the value of the longest float prefix

                      //it can find in its argument.

                      retVal = parseFloat(value);

          }

     

          return retVal;

    }

     

    /*------------------------------------------------------------------------------

          convertJScriptNumberToXML()

    ------------------------------------------------------------------------------*/

    function convertJScriptNumberToXML(value)

    {

          var retVal;

     

          switch (value)

          {

                case Number.NEGATIVE_INFINITY:

                      retVal = "-INF";

                      break;

     

                case Number.POSITIVE_INFINITY:

                      retVal = "INF";

                      break;

     

                //NaN == NaN returns false. Any other value is equal to itself,

                //which is why the case below differentiates between NaN and

                //any other valid value

                case value:

                      retVal = value;

                      break;

     

                default:

                      retVal = "NaN";

          }

     

          return retVal;

    }

     

    /* =============================================================================

          Node value operations

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          isInvalidOrEmpty()

    ------------------------------------------------------------------------------*/

    function isInvalidOrEmpty(xmlNode)

    {

          // If there is no value, ignore it.

          if (!xmlNode || !xmlNode.text)

                return true;

     

          // The caller can pass additional error types as optional arguments.

          var aErrorTypes = new Array;

          if (arguments.length > 1)

          {

                for (var i=1; i<arguments.length; i++)

                      aErrorTypes.push(arguments[i]);

          }

          else

          {

                aErrorTypes.push("SCHEMA_VALIDATION");

          }

     

          // If there is a validation error related to this node,

          // then the node is invalid.

          for (var i=0; i<XDocument.Errors.Count; i++)

          {

                var oError = XDocument.Errors(i);

     

                if (xmlNode == oError.Node)

                {

                      for (var j in aErrorTypes)

                      {

                            if (oError.Type == aErrorTypes[j])

                                  return true;

                      }

                }

          }

     

          // Is valid (no error was found).

          return false;

    }

     

    /*------------------------------------------------------------------------------

          getNodeValue()

    ------------------------------------------------------------------------------*/

    function getNodeValue(xpath, defaultValue)

    {

          var xmlNode = getNode(xpath);

     

          if (isInvalidOrEmpty(xmlNode))

                return (arguments.length > 1) ? defaultValue : "";

          else

                return xmlNode.text;

    }

     

    /*------------------------------------------------------------------------------

          getNodeTypedValue()     - Use instead of getNodeValue() if you want

                to parse the value by MSXML according to data type (from schema).

               

          NOTE: this is not really useful for dates in Jscript.

    ------------------------------------------------------------------------------*/

    function getNodeTypedValue(xpath, defaultValue, fNumber)

    {

          var xmlNode = getNode(xpath);

     

          if (isInvalidOrEmpty(xmlNode))

                return (arguments.length > 1) ? defaultValue : "";

         

          if (fNumber)

                return convertXMLNumberToJScript(xmlNode.nodeTypedValue);

          else

                return xmlNode.nodeTypedValue;

    }

     

    /*------------------------------------------------------------------------------

          setNodeValue()

    ------------------------------------------------------------------------------*/

    function setNodeValue(xpath, value)

    {

          var xmlNode = getNode(xpath);

     

          if (!xmlNode)

                return;

     

          // The xsi:nil needs to be removed before we set the value.

          if (value != "" && xmlNode.getAttribute("xsi:nil"))

                xmlNode.removeAttribute("xsi:nil");

     

          // Setting the value would mark the document as dirty.

          // Let's do that if the value has really changed.

          if (xmlNode.text != value)

                xmlNode.text = value;

    }

     

    /*------------------------------------------------------------------------------

          setNodeTypedValue() - Use instead of setNodeValue() if you want

                to format the value by MSXML according to data type (from schema).

               

                Use this when setting floating point and decimal values. These

                values are formatted differently in some locales and will cause schema

                validation errors when set using setNodeValue or a node's text property.

               

          NOTE: this is not really useful for dates in Jscript.

    ------------------------------------------------------------------------------*/

    function setNodeTypedValue(xpath, value)

    {

          var xmlNode = getNode(xpath);

         

          if (!xmlNode)

                return;

     

          // The xsi:nil needs to be removed before we set the value.

          if (value != "" && xmlNode.getAttribute("xsi:nil"))

                xmlNode.removeAttribute("xsi:nil");

     

          var convertedValue = convertJScriptNumberToXML(value);

     

          // Setting the value would mark the document as dirty.

          // Let's do that if the value has really changed.

          if (xmlNode.nodeTypedValue != convertedValue)

                xmlNode.nodeTypedValue = convertedValue;

    }

     

    /*------------------------------------------------------------------------------

          setRoundedValue() - Rounds the value to the default number of decimal

          places and calls setNodeTypedValue() with the result.

    ------------------------------------------------------------------------------*/

    function setRoundedValue(xpath, value)

    {

          var xmlNode = getNode(xpath);

     

          if (!xmlNode)

                return;

     

          var roundedValue = roundFloat(value, 3);

          setNodeTypedValue(xpath, roundedValue);

    }

     

    /*------------------------------------------------------------------------------

          setNil() - Empty a nillable element.

    ------------------------------------------------------------------------------*/

    function setNil(xpath)

    {

          var xmlNode = getNode(xpath);

     

          if (!xmlNode || xmlNode.text === "")

                return;

     

          // Create xsi:nil attribute with the proper namespace.

          var xmlNil = xmlNode.ownerDocument.createNode(2, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance");

          xmlNil.text = "true";

     

          // The order is important.

          xmlNode.text = "";

          xmlNode.setAttributeNode(xmlNil);

    }

     

    /*------------------------------------------------------------------------------

          roundFloat() - Rounds the value to the specified number of decimal places.

    ------------------------------------------------------------------------------*/

    function roundFloat(value, decimalPlaces)

    {

          if (value < -1E15 || 1E15 < value)

          {

                return value;

          }

          else

          {

                var nPowerToRound = Math.pow(10, decimalPlaces);

                return Math.round(value*nPowerToRound)/nPowerToRound;

          }

    }

     

    /*------------------------------------------------------------------------------

          normalizeSource() - Ensures that we always get a node of type NODE_ELEMENT

                or NODE_ATTRIBUTE.

    ------------------------------------------------------------------------------*/

    function normalizeSource(oEvent)

    {

          // Return the node's parent if the node is of type NODE_TEXT and its parent

          // is of type NODE_ELEMENT

          if (oEvent.Parent.nodeType == 1 && oEvent.Source.nodeType == 3)

                return oEvent.Parent;

               

          // Return the node if it is of type NODE_ELEMENT or NODE_ATTRIBUTE;

          if (oEvent.Source.nodeType == 1 || oEvent.Source.nodeType == 2)

                return oEvent.Source;

    }

     

    /*------------------------------------------------------------------------------

          normalizeParent() - Ensures that we always get the parent of a node of

                type NODE_ELEMENT or NODE_ATTRIBUTE.

    ------------------------------------------------------------------------------*/

    function normalizeParent(oEvent)

    {

          // Return the node if it is of type NODE_ELEMENT or NODE_ATTRIBUTE;

          if (oEvent.Source.nodeType == 1 || oEvent.Source.nodeType == 2)

                return oEvent.Parent;

               

          // Return the node 's parent if the node is of type NODE_TEXT and its parent

          // is of type NODE_ELEMENT

          if (oEvent.Parent.nodeType == 1 && oEvent.Source.nodeType == 3)

                return oEvent.Parent.parentNode;

    }

     

    /*------------------------------------------------------------------------------

          initializeNodeValue()

    ------------------------------------------------------------------------------*/

    function initializeNodeValue(xpath, strValue)

    {

          var xmlNode = getNode(xpath);

     

          // Set the node value *ONLY* if the node is empty.

    //    if (xmlNode.text == "")

    //          setNodeValue(xmlNode, strValue);

    }

     

    /* =============================================================================

          Simple nodelist operations

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          getNode()

    ------------------------------------------------------------------------------*/

    function getNode(xpath)

    {

          // Both XML node and absolute XPath are allowed.

          if (typeof(xpath) == "string")

                return XDocument.DOM.selectSingleNode(xpath);

          else

                return xpath;

    }

     

    /*------------------------------------------------------------------------------

          getNodeList()

    ------------------------------------------------------------------------------*/

    function getNodeList(xpath)

    {

          // Both XML node and absolute XPath are allowed.

          if (typeof(xpath) == "string")

                return XDocument.DOM.selectNodes(xpath);

          else

                return xpath;

    }

     

    /*------------------------------------------------------------------------------

          count()

    ------------------------------------------------------------------------------*/

    function count(xpath)

    {

          var xmlNodeList = getNodeList(xpath);

     

          if (xmlNodeList)

                return xmlNodeList.length;

          else

                return -1;

    }

     

    /* =============================================================================

          Complex nodelist operations

    ============================================================================= */

     

    /*------------------------------------------------------------------------------

          applyAction() - Iterate the whole nodelist and apply a given action

                to each node in the nodelist. You can implement your own actions.

     

          Example:

                var oAction = new Object();

                oAction.sum = 0;

                oAction.apply = new Function("xmlNode", "this.sum += xmlNode.nodeTypedValue");

    ------------------------------------------------------------------------------*/

    function applyAction(xpath, oAction)

    {

          var xmlNodeList = getNodeList(xpath);

          var xmlNode;

     

          while (xmlNode = xmlNodeList.nextNode())

                oAction.apply(xmlNode);

     

          xmlNodeList.reset();

    }

     

    /*------------------------------------------------------------------------------

          sum()

    ------------------------------------------------------------------------------*/

    function sum(xpath)

    {

          var oAction = new Object;

          oAction.nResult = 0;

          oAction.apply = new Function("xmlNode", "this.nResult += getNodeTypedValue(xmlNode, 0, true)");

     

          applyAction(xpath, oAction);

          return oAction.nResult;

    }

     

    /*------------------------------------------------------------------------------

          anyInvalidOrEmpty() - Searches a nodelist to see if there are any invalid

                or empty nodes.

    ------------------------------------------------------------------------------*/

    function anyInvalidOrEmpty(xpath)

    {

          var oAction = new Object;

          oAction.fInvalid = false;

          oAction.apply = new Function("xmlNode", "this.fInvalid |= isInvalidOrEmpty(xmlNode)");

         

          applyAction(xpath, oAction);

          return oAction.fInvalid;

    }

     

    /*------------------------------------------------------------------------------

          reindex()

    ------------------------------------------------------------------------------*/

    function reindex(xpath, iStart)

    {

          if (iStart == null)

                iStart = 1;

     

          var oAction = new Object;

          oAction.i = iStart;

          oAction.apply = new Function("xmlNode", "setNodeTypedValue(xmlNode, this.i++)");

     

          return applyAction(xpath, oAction);

    }

     

    /*------------------------------------------------------------------------------

          average()

    ------------------------------------------------------------------------------*/

    function average(xpath, xpathWeights)

    {

          var oAction = new Object;

          oAction.nSum = 0;

          oAction.cNodes = 0;

     

          if (!xpathWeights)

          {

                oAction.apply = actionSimpleAverage;

                oAction.result = resultSimpleAverage;

          }

          else

          {

                oAction.nWeights = 0;

                oAction.xmlWeights = getNodeList(xpathWeights);

                oAction.apply = actionWeightedAverage;

                oAction.result = resultWeightedAverage;

          }

     

          applyAction(xpath, oAction);

          return oAction.result();

    }

     

    /*------------------------------------------------------------------------------

          actionSimpleAverage()

    ------------------------------------------------------------------------------*/

    function actionSimpleAverage(xmlNode)

    {

          if (!isInvalidOrEmpty(xmlNode))

          {

                this.nSum += getNodeTypedValue(xmlNode, 0, true);

                this.cNodes++;

          }

    }

     

    /*------------------------------------------------------------------------------

          resultSimpleAverage()

    ------------------------------------------------------------------------------*/

    function resultSimpleAverage()

    {

          if (this.cNodes)

                return this.nSum / this.cNodes;

          else

                return 0;

    }

     

    /*------------------------------------------------------------------------------

          actionWeightedAverage()

    ------------------------------------------------------------------------------*/

    function actionWeightedAverage(xmlNode)

    {

          // There should be one weight for each node. Even if the node is invalid,

          // we have to advance the iterator of weights to keep them in sync.

          var xmlWeight = this.xmlWeights.nextNode();

     

          if (!isInvalidOrEmpty(xmlNode) && !isInvalidOrEmpty(xmlWeight))

          {

                var nValue = getNodeTypedValue(xmlNode, 0, true);

                var nWeight = getNodeTypedValue(xmlWeight, 1, true);

     

                this.nSum += nValue * nWeight;

                this.nWeights += nWeight;

                this.cNodes++;

          }

    }

     

    /*------------------------------------------------------------------------------

          resultWeightedAverage()

    ------------------------------------------------------------------------------*/

    function resultWeightedAverage()

    {

          this.xmlWeights.reset();

     

          if (this.cNodes)

          {

                if (this.nWeights > 0)

                      return this.nSum / this.nWeights;

                else

                      return this.nSum

          }

          else

          {

                return 0;

          }

    }

     

    /*------------------------------------------------------------------------------

          sort()

    ------------------------------------------------------------------------------*/

    function sort(xpathParent, xpathChildren, fnCompare)

    {

          // Retrieve the parent node; all the children will be sorted.

          var xmlOrigParent = getNode(xpathParent)

          var xmlItems = xmlOrigParent.selectNodes(xpathChildren);

     

          if (1 < count(xmlItems))

          {

                // Store the (pointers to) items in an array for faster access.

                rgItems = new Array();

               

                while (xmlItem = xmlItems.nextNode())

                      rgItems.push(xmlItem);

                     

                // Sort the array (the XML does not change).

                rgItems.sort(fnCompare);

     

                // Now that the array is sorted the DOM should be updated.

                var xmlSortParent = xmlOrigParent.cloneNode(true);

                var xmlClones = xmlSortParent.selectNodes(xpathChildren);

                xmlClones.removeAll();

               

                // Update the nodelist, each item is moved only once.

                // (each change is causing several notifications to be fired.)

                for (var i=0; i<rgItems.length; i++)

                      xmlSortParent.appendChild(rgItems[i].cloneNode(true));

               

                xmlOrigParent.parentNode.replaceChild(xmlSortParent, xmlOrigParent);

          }

    }

     

  • 04-14-2008 12:05 PM In reply to

    Re: removing xml attachment when i email a form

    I have not tried this but possibly you could set the field your attachment control is bound to to blank.

    Otherwise copy your controls to a new view and set it up the way you want it.

    Create a field which tracks the state and set it to 'readonly' right before the email submit.

    Put a rule in the open rules if state = readonly then switch to readonly view.

  • 04-14-2008 01:24 PM In reply to

    Re: removing xml attachment when i email a form

    When the form is sent, Infopath is generating an XML attachemnt. I am not telling it to attach anything, it's doing it by default, so there are no specific controlls associated with it. When you are saying " set the field your attachment control is bound to to blank" I am not sure which control are you reffering to.

    My goal is to have an email with not attachments, just static data of the form itself, with no attachement that user can open.

    I tried a read-only view approach, but it doesn't help getting rid of XML attachment, it just changes the view how users see form in their email.

  • 04-15-2008 09:31 AM In reply to

    Re: removing xml attachment when i email a form

    OK sorry I thought you were referring to an attachment within the form.

    In 2003 you do not have an option not to to attach the xml like you do in2007.

    You can either use code to generate your own email or a mailto hyperlink may work for you. It depends on whether you just want a notifivation with a hyperlink or what.

  • 04-30-2008 06:19 AM In reply to

    Re: removing xml attachment when i email a form

    Clay,

      Appreciate the response, what is meant by mail to hyperlink? Will that keep the form embedded in the email when sent out or will it attach as a hypelink? How would i go about setting one up?

  • 04-30-2008 07:27 AM In reply to

    Re: removing xml attachment when i email a form

    http://www.addressmunger.com/mailto_syntax_tutorial/

    This would be to start an email in there defautl browser. I beleive you can embed a hyperlink in the body or subject.

    Since you are naming the file and submitting it you can pass that URL into the this hyperlink via concatenation.

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