如何在 CRM 标注中附加到表单上的字段?

发布于 2024-09-10 13:22:08 字数 1705 浏览 7 评论 0原文

我找不到任何有关此的信息。我有一个从表单触发的 CRM 标注,我需要附加到其中一个字段;例如,该字段中可能有类似“BH”的内容,我需要标注来进行一些计算并更改该字段,以便它读取“BH002129”或其他内容,但无论我如何尝试,它最终都只是完全覆盖该字段(因此在这种情况下,它只会显示“002129”)。我似乎无法将其附加,而且我也无法弄清楚如何读取该属性的值,因此我可以将其附加到标注放置在那里的字符串上。必须有办法做到这一点,对吧?但如何呢?

编辑:代码片段:


public override PreCalloutReturnValue PreCreate(CalloutUserContext userContext, CalloutEntityContext entityContext, ref string entityXml, ref string errorMessage)
  {
  // Variables
   string prefix = "no_init";

   XmlDocument entityDoc = new XmlDocument();
   entityDoc.LoadXml(entityXml);

   XmlNodeList propertyList = entityDoc.GetElementsByTagName("Property");
   XmlElement competitorNumberValue = null;
   XmlElement properties = (XmlElement) entityDoc.GetElementsByTagName("Properties")[0];
   XmlElement competitorNumberElement = entityDoc.CreateElement("Property");

   // Find prefix -- this is the part I don't know how to do
   prefix = Convert.ToString(?????);

           /*
               Other stuff gets calculated here, which works fine. New value gets written to the attribute here as well.
           */

   return PreCalloutReturnValue.Continue;   
  }

另一个编辑:我刚刚尝试了这个想法,我在网上找到了这个想法,这实际上会导致保存时出现 CRM 服务器错误:



            string nameSpaceValue = entityDoc.ChildNodes[0].Attributes["xmlns"].Value;
            XmlNamespaceManager xsn = new XmlNamespaceManager(entityDoc.NameTable);
            xsn.AddNamespace("z", nameSpaceValue);   
            string entityXpath = "//z:new_name";
            XmlNode new_nameNode = entityDoc.SelectSingleNode(entityXpath, xsn);

            // Find prefix
            prefix = ((XmlElement)new_nameNode).GetAttribute("new_name").ToString();

I can't find any information about this. I've got a CRM callout that fires from a form, and I need append to one of the fields; for example, the field might have something like "BH" in it, and I need the callout to do some calculations and alter the field so that it reads "BH002129" or whatever, but no matter how I try it, it ends up just overwriting the field entirely (so in that case, it will just say "002129"). I can't seem to get it to append, and I also can't figure out how to read the value of that attribute so I can just tack it on to the string that the callout puts there. There has to be a way to do this, right? But how?

Edit: Code snippet:


public override PreCalloutReturnValue PreCreate(CalloutUserContext userContext, CalloutEntityContext entityContext, ref string entityXml, ref string errorMessage)
  {
  // Variables
   string prefix = "no_init";

   XmlDocument entityDoc = new XmlDocument();
   entityDoc.LoadXml(entityXml);

   XmlNodeList propertyList = entityDoc.GetElementsByTagName("Property");
   XmlElement competitorNumberValue = null;
   XmlElement properties = (XmlElement) entityDoc.GetElementsByTagName("Properties")[0];
   XmlElement competitorNumberElement = entityDoc.CreateElement("Property");

   // Find prefix -- this is the part I don't know how to do
   prefix = Convert.ToString(?????);

           /*
               Other stuff gets calculated here, which works fine. New value gets written to the attribute here as well.
           */

   return PreCalloutReturnValue.Continue;   
  }

Another edit: I just tried this idea, which I found online and which actually causes a CRM server error on save:



            string nameSpaceValue = entityDoc.ChildNodes[0].Attributes["xmlns"].Value;
            XmlNamespaceManager xsn = new XmlNamespaceManager(entityDoc.NameTable);
            xsn.AddNamespace("z", nameSpaceValue);   
            string entityXpath = "//z:new_name";
            XmlNode new_nameNode = entityDoc.SelectSingleNode(entityXpath, xsn);

            // Find prefix
            prefix = ((XmlElement)new_nameNode).GetAttribute("new_name").ToString();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无言温柔 2024-09-17 13:22:09

我使用此类来处理标注实体 xml

public abstract class EntityXmlParser
{
    public abstract bool isValueExists(params string[] arrParamName);
    public abstract string GetSingleValue(string sParamName, string sDefaultValue);
    public abstract int GetSingleValue(string sParamName, int nDefaultValue);
    public abstract decimal GetSingleValue(string sParamName, decimal nDefaultValue);
    public abstract Guid GetSingleValue(string sParamName, Guid idDefaultValue);
    public abstract DateTime GetSingleValue(string sParamName, DateTime dtDefaultValue);
}

public class EntityCrmCalloutXmlParser : EntityXmlParser
{
    private XmlDocument m_xmlDoc = null;
    private NameTable m_xmlNameTable = null;
    private XmlNamespaceManager m_xmlNameMgr = null;
    private const string ms_sURIXmlns = @"http://schemas.microsoft.com/crm/2006/WebServices";
    private const string ms_sURIXsi = @"http://www.w3.org/2001/XMLSchema-instance";
    private bool m_blChangeEntityXml = false;

public EntityCrmCalloutXmlParser(string sCalloutEntityXml)
{
    /*m_xd = new XPathDocument(new System.IO.StringReader(sCalloutEntityXml));
    m_xn = m_xd.CreateNavigator();*/
    m_xmlNameTable = new NameTable();
    m_xmlNameMgr = new XmlNamespaceManager(m_xmlNameTable);
    // Add the required prefix/namespace pairs to the namespace manager. Add a default namespace first.
    m_xmlNameMgr.AddNamespace("crm", ms_sURIXmlns);
    m_xmlNameMgr.AddNamespace("xsi", ms_sURIXsi);
    // загрузка xml-строки
    m_xmlDoc = new XmlDocument();
    m_xmlDoc.LoadXml(sCalloutEntityXml);
}

public string EntityXml
{
    get { return m_xmlDoc.OuterXml; }
}

public bool IsChangeEntityXml
{
    get { return m_blChangeEntityXml; }
}

public string GetEntityName()
{
    XmlNodeList xmllstItem = m_xmlDoc.SelectNodes("/crm:BusinessEntity/@Name", m_xmlNameMgr);
    if ((null == xmllstItem) || (1 != xmllstItem.Count))
        throw new CrmInternalException("Название сущности не найдено.");
    return xmllstItem[0].InnerText;
}

public override string GetSingleValue(string sParamName, string sDefaultValue)
{
    XmlNodeList xiter = m_xmlDoc.SelectNodes("//crm:Property[@Name='" + sParamName + "']/crm:Value", m_xmlNameMgr);
    if (0 == xiter.Count)
        return sDefaultValue;
    if ((1 != xiter.Count) /* || !xiter.MoveNext()*/)
        throw new System.ApplicationException("Ошибка при разборе входных значений. Неудалось однозначно определить параметр '" + sParamName + "'.");
    // проверка на значение null.
    XmlAttribute xmlIsNullAttribute = xiter.Item(0).Attributes["IsNull"];
    bool blNull = false;
    if (null != xmlIsNullAttribute)
        blNull = bool.Parse(xiter.Item(0).Attributes["IsNull"].Value);
    return (blNull) ? sDefaultValue : xiter.Item(0).InnerText;
}
public override Guid GetSingleValue(string sParamName, Guid idDefaultValue)
{
    return new Guid(GetSingleValue(sParamName, idDefaultValue.ToString("B")));
}

public override decimal GetSingleValue(string sParamName, decimal nDefaultValue)
{
    return decimal.Parse(GetSingleValue(sParamName, nDefaultValue.ToString(CalloutManager.Instance.NumberFormatInfo)), CalloutManager.Instance.NumberFormatInfo);
}

public override int GetSingleValue(string sParamName, int nDefaultValue)
{
    return int.Parse(GetSingleValue(sParamName, nDefaultValue.ToString()));
}

public override DateTime GetSingleValue(string sParamName, DateTime dtDefaultValue)
{
    return DateTime.Parse(GetSingleValue(sParamName, dtDefaultValue.ToString(CalloutManager.Instance.CRMFullDateFormat)));
}

    public bool SetPropertyValue(string sPropertyName, DateTime dtPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new ApplicationException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmDateTimeProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        if (DateTime.MinValue.Equals(dtPropertyValue))
            xmlPropValueElem.SetAttribute("IsNull", string.Empty, "true");
        else
            xmlPropValueElem.InnerText = dtPropertyValue.ToString("s");

        m_blChangeEntityXml = true;
        return true;
    }


    public bool SetPropertyValue(string sPropertyName, string sPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new ApplicationException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "StringProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = sPropertyValue;
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, Guid idPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "LookupProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        if (idPropertyValue.Equals(Guid.Empty))
            xmlPropValueElem.SetAttribute("IsNull", string.Empty, "true");
        else
            xmlPropValueElem.InnerText = idPropertyValue.ToString("B");
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, int nPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmNumberProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = nPropertyValue.ToString();
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, decimal dPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmMoneyProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = dPropertyValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
        m_blChangeEntityXml = true;
        return true;
    }

}

}

I use this class to work witn callout entity xml

public abstract class EntityXmlParser
{
    public abstract bool isValueExists(params string[] arrParamName);
    public abstract string GetSingleValue(string sParamName, string sDefaultValue);
    public abstract int GetSingleValue(string sParamName, int nDefaultValue);
    public abstract decimal GetSingleValue(string sParamName, decimal nDefaultValue);
    public abstract Guid GetSingleValue(string sParamName, Guid idDefaultValue);
    public abstract DateTime GetSingleValue(string sParamName, DateTime dtDefaultValue);
}

public class EntityCrmCalloutXmlParser : EntityXmlParser
{
    private XmlDocument m_xmlDoc = null;
    private NameTable m_xmlNameTable = null;
    private XmlNamespaceManager m_xmlNameMgr = null;
    private const string ms_sURIXmlns = @"http://schemas.microsoft.com/crm/2006/WebServices";
    private const string ms_sURIXsi = @"http://www.w3.org/2001/XMLSchema-instance";
    private bool m_blChangeEntityXml = false;

public EntityCrmCalloutXmlParser(string sCalloutEntityXml)
{
    /*m_xd = new XPathDocument(new System.IO.StringReader(sCalloutEntityXml));
    m_xn = m_xd.CreateNavigator();*/
    m_xmlNameTable = new NameTable();
    m_xmlNameMgr = new XmlNamespaceManager(m_xmlNameTable);
    // Add the required prefix/namespace pairs to the namespace manager. Add a default namespace first.
    m_xmlNameMgr.AddNamespace("crm", ms_sURIXmlns);
    m_xmlNameMgr.AddNamespace("xsi", ms_sURIXsi);
    // загрузка xml-строки
    m_xmlDoc = new XmlDocument();
    m_xmlDoc.LoadXml(sCalloutEntityXml);
}

public string EntityXml
{
    get { return m_xmlDoc.OuterXml; }
}

public bool IsChangeEntityXml
{
    get { return m_blChangeEntityXml; }
}

public string GetEntityName()
{
    XmlNodeList xmllstItem = m_xmlDoc.SelectNodes("/crm:BusinessEntity/@Name", m_xmlNameMgr);
    if ((null == xmllstItem) || (1 != xmllstItem.Count))
        throw new CrmInternalException("Название сущности не найдено.");
    return xmllstItem[0].InnerText;
}

public override string GetSingleValue(string sParamName, string sDefaultValue)
{
    XmlNodeList xiter = m_xmlDoc.SelectNodes("//crm:Property[@Name='" + sParamName + "']/crm:Value", m_xmlNameMgr);
    if (0 == xiter.Count)
        return sDefaultValue;
    if ((1 != xiter.Count) /* || !xiter.MoveNext()*/)
        throw new System.ApplicationException("Ошибка при разборе входных значений. Неудалось однозначно определить параметр '" + sParamName + "'.");
    // проверка на значение null.
    XmlAttribute xmlIsNullAttribute = xiter.Item(0).Attributes["IsNull"];
    bool blNull = false;
    if (null != xmlIsNullAttribute)
        blNull = bool.Parse(xiter.Item(0).Attributes["IsNull"].Value);
    return (blNull) ? sDefaultValue : xiter.Item(0).InnerText;
}
public override Guid GetSingleValue(string sParamName, Guid idDefaultValue)
{
    return new Guid(GetSingleValue(sParamName, idDefaultValue.ToString("B")));
}

public override decimal GetSingleValue(string sParamName, decimal nDefaultValue)
{
    return decimal.Parse(GetSingleValue(sParamName, nDefaultValue.ToString(CalloutManager.Instance.NumberFormatInfo)), CalloutManager.Instance.NumberFormatInfo);
}

public override int GetSingleValue(string sParamName, int nDefaultValue)
{
    return int.Parse(GetSingleValue(sParamName, nDefaultValue.ToString()));
}

public override DateTime GetSingleValue(string sParamName, DateTime dtDefaultValue)
{
    return DateTime.Parse(GetSingleValue(sParamName, dtDefaultValue.ToString(CalloutManager.Instance.CRMFullDateFormat)));
}

    public bool SetPropertyValue(string sPropertyName, DateTime dtPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new ApplicationException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmDateTimeProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        if (DateTime.MinValue.Equals(dtPropertyValue))
            xmlPropValueElem.SetAttribute("IsNull", string.Empty, "true");
        else
            xmlPropValueElem.InnerText = dtPropertyValue.ToString("s");

        m_blChangeEntityXml = true;
        return true;
    }


    public bool SetPropertyValue(string sPropertyName, string sPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new ApplicationException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "StringProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = sPropertyValue;
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, Guid idPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "LookupProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        if (idPropertyValue.Equals(Guid.Empty))
            xmlPropValueElem.SetAttribute("IsNull", string.Empty, "true");
        else
            xmlPropValueElem.InnerText = idPropertyValue.ToString("B");
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, int nPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmNumberProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = nPropertyValue.ToString();
        m_blChangeEntityXml = true;
        return true;
    }

    public bool SetPropertyValue(string sPropertyName, decimal dPropertyValue)
    {
        XmlNode xmlRootPropNode = m_xmlDoc.SelectSingleNode("crm:BusinessEntity/crm:Properties", m_xmlNameMgr);
        if (null == xmlRootPropNode)
            throw new CrmInternalException("Ошибка при получении xml элемента BusinessEntity.");
        // поиск элемента в xml-структуре
        XmlElement xmlPropValueElem = (XmlElement)xmlRootPropNode.SelectSingleNode("crm:Property[@Name='" + sPropertyName + @"']/crm:Value", m_xmlNameMgr);
        if (null == xmlPropValueElem)
        {   // элемент не найден
            // создание элемента
            XmlElement xmlPropElem = (XmlElement)xmlRootPropNode.AppendChild(m_xmlDoc.CreateElement("Property", ms_sURIXmlns));
            xmlPropElem.SetAttribute("type", ms_sURIXsi, "CrmMoneyProperty");
            xmlPropElem.SetAttribute("Name", sPropertyName);
            xmlPropValueElem = (XmlElement)xmlPropElem.AppendChild(m_xmlDoc.CreateElement("Value", ms_sURIXmlns));
        }
        xmlPropValueElem.InnerText = dPropertyValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
        m_blChangeEntityXml = true;
        return true;
    }

}

}

相思碎 2024-09-17 13:22:09

我认为您应该将其包装在动态实体中,以便您可以直接访问每个属性。

看看链接

I think that you should wrap this inside a Dynamic entity so that you can acces directly each properties.

Take a look at Link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文