繁体   English   中英

在Dynamics CRM中添加部分图标并更改背景颜色

[英]Adding section icons and changing background color in dynamics CRM

我需要为实体中的每个部分提供一个图标。 例如,我需要为“一般信息”提供一个图标,为“交互”部分提供另一个图标。 是否有关于我该怎么做的想法? 请问如何为每个部分设置背景颜色? 提前致谢,

无法将图标分配给各节。 最好的办法是在每个部分中添加一个Web资源,并使它们链接到图像,但这听起来并不是您想要的。

没有支持的方法来修改表单背景色。 但是,如果您不关心仍受支持,则可以使用jQuery来实现。 将此函数放入表单脚本中:

function changeSectionBackgroundColor(sectionId, color) {
    parent.$("table.ms-crm-FormSection[name='"+sectionId+"']").css({"background-color": color});
}

并像这样使用它:

changeSectionBackgroundColor("General_Section_2", "red");
changeSectionBackgroundColor("General_Section_2", "#ababab");

您可以尝试执行以下操作以插入“节”图像:

var stackoverflow = (function (Xrm)
{
    var sectionBarClassName = '.ms-crm-Form-SectionBar';                // name of the CSS class given to the Section's Label's <td> element

    function GetSection(tabName, sectionName)
    {
        var parentTab = Xrm.Page.ui.tabs.getByName(tabName);            // get the tab
        var section = parentTab.sections.getByName(sectionName);        // get the section

        return section;
    }

    function AddSectionImage(tabName, sectionName, imageUrl)
    {
        var section = GetSection(tabName, sectionName);                // retrieve section using Xrm
        var elSection = document.querySelector('table[name=' + section.getKey() + ']');
        var elSectionHeader = elSection.querySelector('tr:first-child');
        var elTitles = elSection.querySelectorAll(sectionBarClassName);
        if (elTitles.length === 1)                                     // we can assume that this section has a title
        {
            var elImg = document.createElement('img');
            elImg.src = imageUrl;
            elTitles[0].insertBefore(elImg, elTitles[0].firstChild);
        }
    }

    return {
        AddSectionImage : AddSectionImage
    };

})(Xrm);

然后,您调用此代码,并传入选项卡和部分的“名称”(而非标签)以及要显示的图像的相对URL。 像这样:

stackoverflow.AddSectionImage('tab_5', 'tab_5_section_1', '/imgs/Cancel_16.png');

我仅在CRM 2016(在线)中测试了此代码。 而且图像有点粗糙。 您需要自己照顾样式(内联)和大小。

当然,这不受Microsoft支持:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM