Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kris Janssen 210 posts 569 karma points c-trib
    Feb 25, 2014 @ 01:53
    Kris Janssen
    0

    Issues with custom Workflow

    I have a form that uses a checkboxlist (with string pre values).

    This form produces following record:

    <uformrecord>
    <state>Approved</state>
    <created>2014-02-24T21:58:49</created>
    <updated>2014-02-24T21:58:49</updated>
    <id>e03faef7-ffa4-4002-ad32-367b2425caad</id>
    <ip>xx.xx.xx.xx</ip>
    <pageid url="/management.aspx" name="Management">1470</pageid>
    <memberkey email="[email protected]" login="xxx">1223</memberkey>
    <fields>
      <membergroups record="e03faef7-ffa4-4002-ad32-367b2425caad" sortorder="0" pageindex="0" fieldsetindex="0">
        <key>472f9167-8719-4d21-a336-9f29dcb0edaa</key>
        <fieldKey>26dd15a7-372d-47ee-a19d-f16a9b63d391</fieldKey>
        <caption>Member Groups</caption>
        <datatype>String</datatype>
        <values>
          <value key="Manager"><![CDATA[Catsense Manager]]></value>
          <value key="Main Partners"><![CDATA[Main Partners]]></value>
          <value key="Associated Partners"><![CDATA[Associated Partners]]></value>
          <value key="MGR"><![CDATA[KUL]]></value>
        </values>
      </membergroups>
      <subject record="e03faef7-ffa4-4002-ad32-367b2425caad" sortorder="1" pageindex="0" fieldsetindex="0">
        <key>67be44ce-e7e6-4ddc-9830-1a10de6c79dc</key>
        <fieldKey>1b8299e9-6ba3-46a5-b7a3-c1f1bba515cd</fieldKey>
        <caption>Subject</caption>
        <datatype>String</datatype>
        <values>
          <value><![CDATA[Test]]></value>
        </values>
      </subject>
      <message record="e03faef7-ffa4-4002-ad32-367b2425caad" sortorder="2" pageindex="0" fieldsetindex="0">
      <key>37a8c32e-825a-4ca8-af5d-d692e8f17df6</key>
        <fieldKey>3ef1b641-a64f-4f57-84e4-970844cfaa03</fieldKey>
        <caption>Message</caption>
        <datatype>String</datatype>
        <values>
          <value><![CDATA[Test 1 2 3]]></value>
        </values>
      </message>
    </fields>
    

    I have created a custom WorkflowType that is needed to send a custom Email to members of my site.

    In fact,

    <membergroups record="e03faef7-ffa4-4002-ad32-367b2425caad" sortorder="0" pageindex="0" fieldsetindex="0">
        <key>472f9167-8719-4d21-a336-9f29dcb0edaa</key>
        <fieldKey>26dd15a7-372d-47ee-a19d-f16a9b63d391</fieldKey>
        <caption>Member Groups</caption>
        <datatype>String</datatype>
        <values>
          <value key="Manager"><![CDATA[Catsense Manager]]></value>
          <value key="Main Partners"><![CDATA[Main Partners]]></value>
          <value key="Associated Partners"><![CDATA[Associated Partners]]></value>
          <value key="MGR"><![CDATA[KUL]]></value>
        </values>
      </membergroups>
    

    Contains an enumeration of the "Roles" for my site.

    The important part of my WorkflowType:

    public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
    
            try
            {
                SendMail("some [email protected]", record.GetRecordField("subject").ValuesAsString(), record.GetRecordField("member groups").ValuesAsString());
            }
         }
    

    Just to be clear "SendMail()" works if I leave out the 3rd argument (i.e. replace it by some random string).

    It seems I can extract meaningful record fields for all but "membergroups". I would have expected

    record.GetRecordField("member groups").ValuesAsString()
    

    would have yielded a comma separated list of all values...

    Normally, I would use logging to debug this but it also seems logging is not working on my instance (U6.0.6, Contour 3.0.17). Log files are created but no content is available in them.

  • Kris Janssen 210 posts 569 karma points c-trib
    Feb 25, 2014 @ 03:00
    Kris Janssen
    0

    Did further testing...

    This works:

    private string CreateEmailList(Record record)
        {
            var viewer = new RecordsViewer();
            XmlNode xml = viewer.GetSingleXmlRecord(record, new XmlDocument());
            XPathNavigator navigator = xml.CreateNavigator();
            XPathExpression selectExpression = navigator.Compile("//fields/child::*");
            selectExpression.AddSort("@pageindex", XmlSortOrder.Ascending, XmlCaseOrder.None, string.Empty, XmlDataType.Number);
            selectExpression.AddSort(
                "@fieldsetindex", XmlSortOrder.Ascending, XmlCaseOrder.None, string.Empty, XmlDataType.Number);
            selectExpression.AddSort("@sortorder", XmlSortOrder.Ascending, XmlCaseOrder.None, string.Empty, XmlDataType.Number);
            XPathNodeIterator nodeIterator = navigator.Select(selectExpression);
            List<string> lEmails = new List<string>();
            while (nodeIterator.MoveNext())
            {
                if (nodeIterator.Current == null)
                {
                    continue;
                }
    
                XPathNavigator node = nodeIterator.Current.SelectSingleNode(".//value");
    
                XPathNavigator captionNode = nodeIterator.Current.SelectSingleNode("caption");
                if (captionNode != null)
                {
                    string caption = captionNode.Value;
    
                    if (caption.Contains("Member Groups"))
                    {
                        XPathNodeIterator values = nodeIterator.Current.Select(".//value");
    
                        while (values.MoveNext())
                        {
                            if (values.Current != null)
                            {
                                string[] strUsers = Roles.GetUsersInRole(values.Current.Value);
    
                                foreach (string strUser in strUsers)
                                {
                                    lEmails.Add(Membership.GetUser(strUser).Email);
                                }
                            }
                        }
    
                    }
                }
    
            }
            return String.Join(",", lEmails.ToArray());
        }
    

    But I still want to understand why the "non XPath" way (i.e. by using the Record object and its properties directly) does not work ... The above is much to clunky....

Please Sign in or register to post replies

Write your reply to:

Draft