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)

JavaScript Not Working on On Change

(0) ShareShare
ReportReport
Posted on by

Its quite awkward to ask a newbie kind of question but can anyone help me on it.

I have an optionset field, Sales Stage, where I am capturing the stages of BPF, and I am hiding tabs based on option set values.

JS working fine on form OnLoad and same JS not working on field OnChange. 

Please let me know where I went wrong.

function OnStageShangeHideShowTabs(executionContext)
{   debugger;
    try{   
        var formContext = executionContext.getFormContext();
        if(formContext.getAttribute("css_salesstage") !=null)
        {
            var OptionSetValue = formContext.getAttribute("css_salesstage").getValue();
            if (OptionSetValue != null)
            {
                if (OptionSetValue == 862590003) //PO/Contract Stage
                {
                    formContext.ui.tabs.get("tab_orders").setVisible(true);
                    formContext.ui.tabs.get("tab_Invoice").setVisible(false);
                    formContext.ui.tabs.get("tab_payments").setVisible(false);
                }
                else {
                    if (OptionSetValue == 862590004) //Invoice Stage
                    {
                        formContext.ui.tabs.get("tab_orders").setVisible(false);
                        formContext.ui.tabs.get("tab_Invoice").setVisible(true);
                        formContext.ui.tabs.get("tab_payments").setVisible(false);
                    }
                    else {
                        if (OptionSetValue == 862590005)  //Payment Received Stage
                        {
                            formContext.ui.tabs.get("tab_orders").setVisible(false);
                            formContext.ui.tabs.get("tab_Invoice").setVisible(false);
                            formContext.ui.tabs.get("tab_payments").setVisible(true);
                        }
                        else {
                            formContext.ui.tabs.get("tab_orders").setVisible(false);
                            formContext.ui.tabs.get("tab_Invoice").setVisible(false);
                            formContext.ui.tabs.get("tab_payments").setVisible(false);
                        }
                    }
                }
            }
        }
    }catch(e)
    {
    alert("Error is in OnStageShangeHideShowTabs and error is: " +e);
    }
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    If your script is working on the form load and not working on the fiel change then it clear it's missing value, so I will suggest you to debug your script and see on case of onchange it getting required value properly or not.

    You can use developers tools to debug your code after butting debugger keyword.

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

    Hi ,

    Are you getting any error in the onchange ? or simply its not firing ?

    I am pretty much sure you already debug your code  seems the value you are selecting is not getting and it is not entering the actual logic.

    Please check following -

    1. Try to get value from BPF , if the field not available in the form.

    var OptionSetValue = formContext.getAttribute("header_process_salesstage").getValue();
    
    // Or You may try with this 
    
    var  OptionSetValue = null;
    try {
        OptionSetValue = Xrm.Page.getAttribute("header_process_salesstage").getSelectedOption().value;
    }
    catch (ex) {   
    }
    



    2. Make sure you are getting value in below line -

      if(formContext.getAttribute("css_salesstage") !=null)


  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Seshan D,

    Check that you have included the OnChange Event Handler on your form. You may have forgotten to include this.

  • NODAL Profile Picture
    860 on at

    Hi Seshan,

    Looks like you are on version 9.

    Can you try addOnStagechange event instead.

    Can refer this..

    [View:https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/formcontext-data-process/eventhandlers/addonstagechange]

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi, BPF is very tricky compare to normal form type. All the control in BPF is lazy loading. So only the active stage control will load. Hence you need to have 2 checking, on load and on stage changes to register your event.

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