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)

crmForm to Xrm

(0) ShareShare
ReportReport
Posted on by 185

I am learning to code. Please excuse any mistakes I made in terminology.

I changed the code from crmForm to Xrm and it worked with one form but not with another. They are identical but I cannot seem to find the problem. Here is the beginning of my code, possibly where the error is.

 

old code:

/* Enable/Disable form fields based on Payment Type */

function set_paymenttype() {

switch (crmForm.all.new_paymenttype_optionset.DataValue)

 

new code:

/* Enable/Disable form fields based on Payment Type */

function set_paymenttype() {

switch (Xrm.Page.getAttribute("new_paymenttype_optionset").getValue()){

 

I get the following error message on opening the form.

The was an error with this field's customized event

Field:window

Event:onload

Error:'set_paymenttype' is undefined

Followed by:

The was an error with this field's customized event

Field:crmForm

Event:onsave

Error:'Form_onsave' is undefined.

 

Here is the updated code for 'Form_onsave'

function Form_onsave() {

Xrm.Page.getAttribute("new_totalleasepayment").setSubmitMode("always");

Xrm.Page.getAttribute("new_estsaleprofit.setSubmitMode("always");

Xrm.Page.getAttribute("new_estsaleprofitmargin.setSubmitMode("always"); }

 

Here are the Event Handlers properties for both events.

6201.event-handler-2.PNG

 

  

Let me know if you need any more information. The rest of the code is not every long. I can upload it if necessary.

Thank you for any assistance in this matter.

*This post is locked for comments

I have the same question (0)
  • dellis Profile Picture
    185 on at

    I want to mention that the code fix for my first project came from another user on this forum. It worked perfectly. This is my attempt to fix my second issue based upon the changes made by the other user.

  • dellis Profile Picture
    185 on at

    Typos! Thank you so much. I've been starting at this for days and you'd think I'd notice. I appreciate it. The onload is still acting up. Here's the code in its entirety.

    function Form_onsave()

    {

      Xrm.Page.getAttribute("new_totalleasepayment").setSubmitMode("always");

      Xrm.Page.getAttribute("new_estsaleprofit.setSubmitMode("always");

      Xrm.Page.getAttribute("new_estsaleprofitmargin.setSubmitMode("always");

    }

    /* Enable/Disable form fields based on Payment Type */

    function Form_onload()

    set_paymenttype()

    {

      switch (Xrm.Page.getAttribute("new_paymenttype_optionset").getValue()){

      case "100000000" /* Lease */:

         trigger_deal_economics(true);

         trigger_lease_economics(true);

         trigger_thirdpartyfinancing(false);

         Xrm.Page.getControl("new_feevolume").setDisabled(true);

         break;

      case "100000001" /* Sale */:

         trigger_deal_economics(true);

         trigger_lease_economics(false);

         trigger_thirdpartyfinancing(false);

         Xrm.Page.getControl("new_feevolume").setDisabled(true);

         break;

      case "100000002" /* Direct Lease-3rd Party */:

         trigger_deal_economics(true);

         trigger_lease_economics(false);

         trigger_thirdpartyfinancing(true);

         Xrm.Page.getControl("new_feevolume").setDisabled(true);

         break;

      case "100000003" /* Fee-Third Party Financing */:

         trigger_deal_economics(false);

         trigger_lease_economics(false);

         trigger_thirdpartyfinancing(false);

         Xrm.Page.getControl("new_salerevenue").setDisabled(false);

         Xrm.Page.getControl("new_feevolume").setDisabled(false);

         break;

      default:

         Xrm.Page.getControl("new_feevolume").setDisabled(true);

         trigger_deal_economics(false);

         trigger_lease_economics(false);

         trigger_thirdpartyfinancing(false);

      }

    }

    function trigger_thirdpartyfinancing(valid)

    {

     if (valid==true)

     {

       Xrm.Page.getControl("new_thirdpartyleaseno").setDisabled(false);

       Xrm.Page.getControl("new_thirdpartyleaseterm").setDisabled(false);

       Xrm.Page.getControl("new_nbvremarketed").setDisabled(false);

     }

     else

     {

       Xrm.Page.getControl("new_thirdpartyleaseno").setDisabled(true);

       Xrm.Page.getControl("new_thirdpartyleaseterm").setDisabled(true);

     }

    }

    function trigger_lease_economics(valid)

    {

     if (valid==true)

     {

       Xrm.Page.getControl("new_estleasepymtbldg").setDisabled(false);

       Xrm.Page.getControl("new_estleasepymtother").setDisabled(false);

       Xrm.Page.getControl("new_leaseterm").setDisabled(false);

       Xrm.Page.getControl("new_newcapx").setDisabled(false);

       Xrm.Page.getControl("new_nbvremarketed").setDisabled(false);

       Xrm.Page.getControl("new_estfinsoftcosts").setDisabled(false);

     }

     else

     {

       Xrm.Page.getControl("new_estleasepymtbldg").setDisabled(true);

       Xrm.Page.getControl("new_estleasepymtother").setDisabled(true);

       Xrm.Page.getControl("new_leaseterm").setDisabled(true);

       Xrm.Page.getControl("new_newcapx").setDisabled(true);

       Xrm.Page.getControl("new_nbvremarketed").setDisabled(true);

       Xrm.Page.getControl("new_estfinsoftcosts").setDisabled(true);

     }

    }

    function trigger_deal_economics(valid)

    {

     if (valid==true)

     {

       Xrm.Page.getControl("new_salerevenue").setDisabled(false);

       Xrm.Page.getControl("new_estcosts").setDisabled(false);

     }

     else

     {

       Xrm.Page.getControl("new_salerevenue").setDisabled(true);

       Xrm.Page.getControl("new_estcosts").setDisabled(true);

     }

    }

    function new_saleprofit_onchange()

    {

      var field1 = Xrm.Page.getAttribute("new_salerevenue").getValue();

      field1 = (field1==null ? 0 : field1);

      var field2 = Xrm.Page.getAttribute("new_estcosts").getValue();

      field2 = (field2==null ? 0 : field2);

      Xrm.Page.getAttribute("new_estsaleprofit").setValue(field1 - field2);

      if (field1 != 0)

      {

        Xrm.Page.getAttribute("new_estsaleprofitmargin").setValue((field1-field2)/field1);

      }

      else

      {

        Xrm.Page.getAttribute("new_estsaleprofitmargin").setValue(0);

      }

    }

    function new_leasepymt_onchange()

    {

      var field1 = Xrm.Page.getAttribute("new_estleasepymtbldg").getValue();

      field1 = (field1==null ? 0 : field1);

      var field2 = Xrm.Page.getAttribute("new_estleasepymtother").getValue();

      field2 = (field2==null ? 0 : field2);

      Xrm.Page.getAttribute("new_totalleasepayment").setValue(field1 + field2);

    }

  • dellis Profile Picture
    185 on at

    I posted the old version of the code. Please ignore the "onsave" section as it is working now.

    Still getting this when the form loads:

    The was an error with this field's customized event

    Field:crmForm

    Event:onsave

    Error:'Form_onsave' is undefined.

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