简体   繁体   English

Microsoft Dynamics 365根据值更改表单上的标题颜色

[英]Microsoft Dynamics 365 Change Header Color on Form based on value

I have an option set on my Account / Sales form. 我在“帐户/销售”表单上设置了一个选项。 Based on this value I want to change the header color at the top of the form. 基于此值,我想更改表单顶部的标题颜色。

I can do this manually through editing the CSS through the Developer Tools, however when I try and do this through Form Properties and Web Resources I cannot get the color to change. 我可以通过开发人员工具编辑CSS来手动完成此操作,但是当我尝试通过“表单属性”和“ Web资源”执行此操作时,无法更改颜色。

As a base test I'm just trying to inject the CSS into the page through javascript. 作为基础测试,我只是尝试通过javascript将CSS注入页面。

Here is the CSS web resource that I created. 这是我创建的CSS Web资源。

.ms-crm-Form-HeaderPosition {
    background-color: rgba(2,206,239,1) !important;
}

Here is the javascript web resource I created: 这是我创建的JavaScript网络资源:

function load_css_file(filename){ 
   var fileref = document.createElement("link") 
   fileref.setAttribute("rel", "stylesheet") 
   fileref.setAttribute("type", "text/css") 
   fileref.setAttribute("href", filename) 
   document.getElementsByTagName("head")[0].appendChild(fileref) 
}
function myFormOnLoad(){ 
   load_css_file('/WebResources/aws_ColoredHeaderMGA.css'); 
}

I then went to my Sales form, changed the form properties to load in my Javascript web resource and then told it to call the function myFormOnLoad as on OnLoad even for the form. 然后,我进入“销售”表单,更改了表单属性以将其加载到Javascript Web资源中,然后告诉它即使在表单上myFormOnLoadOnLoad上调用函数myFormOnLoad

I'm not getting any errors, I know the javascript is getting called because I added an alert to it just to make sure and I did receive the alert. 我没有收到任何错误,我知道javascript正在被调用,因为我向其中添加了alert只是为了确保并且确实收到了警报。

What am I missing to get the header color to change? 我缺少什么来改变标题颜色?

jQuery尝试

In case someone is looking for working code, the below one we are using. 如果有人在寻找有效的代码,请使用下面的代码。

I guess the URL is the problem in OP. 我想网址是OP中的问题。 Add OrgName & remove extension (.css) 添加OrgName并删除扩展名(.css)

function LdCSS() {
    var path = "/orgname/WebResources/new_custom";
    var head = document.getElementsByTagName('head')[0];
    var link = document.createElement('link');
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = path;
    link.media = 'all';
    head.appendChild(link);
}

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

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