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)

Check for Information on Close Opportunity as Won

(0) ShareShare
ReportReport
Posted on by 895

Hi,

I am trying to create the Javascript so that when a particular condition is filled it checks some fields to make sure there are values there. The code I am using is:

function Form_onsave(ExecutionObj)
{
 saveMode = ExecutionObj.getEventArgs().getSaveMode();
 Var shouldSave = false;
 if(saveMode == 5)
  {
   if(status == 1)
   { 
    if(Xrm.Page.getAttribute("new_BusinessClassification").getValue() == "Sole Trader")
    {
     if(Xrm.Page.getAttribute("new_dateofbirth").getValue())
     {
      shouldSave = True;
     }
     if(shouldSave == false)
     {
      if(Xrm.Page.getAttribute("new_fullnamerequired").getValue() == '')
      {
       if(Xrm.Page.getAttribute("new_fullhomeaddress").getValue() == '')
       {
       alert("Sole Trader Requires Additional Information");
       executionObj.getEventArgs().preventDefault();
       }
      }
     }
    } 
   }
  }
}

Basically I have an option set on the opportunity form and I need it to check if the Save event is triggered by a Close-Won and if this is a Sole Trader to ensure we have Name, Address and DOB details, when I have loaded this up onto the form then when I open the Opportunity Form I get a "Send Error report" error.

I am very new to using Javascript (About two days) so I am sure I am doing something wrong but I am not entirely sure what.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Gus Gonzalez Profile Picture
    27,113 on at

    Adam,

    Is there any way you can do this via Workflow?

    I.E. If "this information is missing" reopen the opportunity?

    I try to stay away from JScript as much as possible.

  • AdamBrown55 Profile Picture
    895 on at

    Is it possible to have the workflow present a message?

    And can it be set to only fire on Close as Won events?

  • AdamBrown55 Profile Picture
    895 on at

    I tried to set it up as below but when I completed an opportunity as Close- Won nothing happened, am I missing a criteria here?

  • AdamBrown55 Profile Picture
    895 on at

    Looks like it is actually working, I think I may have been a little hasty in seeing if it had reopened.

    Thanks

    Adam

  • Gus Gonzalez Profile Picture
    27,113 on at

    Great, I'm glad that helped. :)

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