web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide and show web resource with javascript code

(0) ShareShare
ReportReport
Posted on by 87

I create 2 webresource and I want when the item of field (option set type) was chosen one of webresource hide.

2018_2D00_06_2D00_13_5F00_17_2D00_07_2D00_38.png

Field name: ClientType

Webresource1: GreenColor

Webresource2: RedColor

2018_2D00_06_2D00_13_5F00_17_2D00_07_2D00_38.png

I don't know the javascript code to fix this problem.

*This post is locked for comments

I have the same question (0)
  • Amin Barek Profile Picture
    87 on at

    this code has a problem

    function choosecolor(){

    var ClientType= Xrm.Page.getAttribute(“new_ ClientType”).getSelectedOption();

    if(ClientType.value==1){

    var control = Xrm.Page.ui.controls.get("WebResource_ GreenColor");

    control.setVisible(false);

    }

    Else if (ClientType.value==2){

    var control = Xrm.Page.ui.controls.get("WebResource_ RedColor");

    control.setVisible(false);

    }

    }

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    In your code the problem is quote signs, also make sure your field name is correct, you can also use getValue simply like below code

    function choosecolor(){

    var ClientType= Xrm.Page.getAttribute("new_ ClientType").getValue();

    if(ClientType==1){

    var control = Xrm.Page.ui.controls.get("WebResource_ GreenColor");

    control.setVisible(false);

    }

    Else if (ClientType==2){

    var control = Xrm.Page.ui.controls.get("WebResource_ RedColor");

    control.setVisible(false);

    }

    }

  • Amin Barek Profile Picture
    87 on at

    Dear Mahen

    I tested it but it had a problem.

    "Script Error

    One of the scripts for this record has caused an error. For more details, download the log file.

    ReferenceError: choosecolor is not defined at eval (eval at RunHandlerInternal (crm.batis.local/.../ClientApiWrapper.aspx), <anonymous>:1:1)"

  • Amin Barek Profile Picture
    87 on at

    2018_2D00_06_2D00_13_5F00_18_2D00_13_2D00_19.png

  • Suggested answer
    Anas Rafik Profile Picture
    365 on at
    function SetFieldInvisibleByVlaue(){
    
    var ClientType= Xrm.Page.getAttribute(“new_ ClientType”).getSelectedOption();
    
    if(ClientType.value==1){
    
    var control = Xrm.Page.ui.controls.get("WebResource_ GreenColor");
    
    control.setVisible(false);
    
    }
    
    else if (ClientType.value==2){
    
    var control = Xrm.Page.ui.controls.get("WebResource_ RedColor");
    
    control.setVisible(false);
    
    }
    
    }

    //the problem is in Else you should type else

  • Gaurav_Pandey09 Profile Picture
    197 on at

    If this a seperate Html webresource that you are opening you probably need to add crm context to your html file.

    Try including the following scriot in your html and then check

    <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Amin ,

    Try with this - 

    function SetFieldInvisibleByVlaue(){ 
        var type = null;
        try {
            type = Xrm.Page.getAttribute("new_ ClientType").getSelectedOption().value; 
        }
        catch (ex) {
            type = null;
        }
       
        if (type != null & type != undefined) {
            if (type == "1"){           
                Xrm.Page.getControl("WebResource_GreenColor").setVisible(false); //Make sure you Replaced correct Web Resource name
     Xrm.Page.getControl("WebResource_RedColor").setVisible(true); //Make sure you Replaced correct Web Resource name

    } else if (type == "2"){
    Xrm.Page.getControl("WebResource_RedColor").setVisible(false); //Make sure you Replaced correct Web Resource name
    Xrm.Page.getControl("WebResource_GreenColor").setVisible(true); //Make sure you Replaced correct Web Resource name

    }
    }
    }
  • Mahendar Pal Profile Picture
    45,095 on at

    Can you please share your latest code, have your corrected quote sign, normally this error occurrs when there is error in quotes or brakets.

  • Amin Barek Profile Picture
    87 on at

    Dear Goutam ,

    Unfortunately it wasn't work

    2018_2D00_06_2D00_14_5F00_10_2D00_35_2D00_13.png

  • Amin Barek Profile Picture
    87 on at

    4201.2018_2D00_06_2D00_14_5F00_10_2D00_35_2D00_13.png

    :-(

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans