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 if competitors has been added to opportunity

(0) ShareShare
ReportReport
Posted on by

I want to check/validate if at least two competitors has been added before completing a specific stage in opportunity BPF. How Can I achieve this? Is it possible to span relationship(from opportunity to competitors)p using business rules

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    M I Mostafa Profile Picture
    4,257 on at

    Hi

    If one opportunity has can have many competitors then you can't use business rules to do that check. The way to achieve this is either using JavaScript API call or a plugin that checks these values.

  • Suggested answer
    Thomas David Dayman Profile Picture
    11,323 on at

    You could try using this JavaScript

    When you load the form it will fetch any competitors attached to the current opportunity and see if the count is less than 2. You can implement lots of ways to stop the user from completing a stage.

    var entity = Xrm.Page.data.entity.getId();
    
    "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"+
    "  <entity name='competitor'>"+
    "    <attribute name='name' />"+
    "    <attribute name='websiteurl' />"+
    "    <attribute name='competitorid' />"+
    "    <order attribute='name' descending='false' />"+
    "    <link-entity name='opportunitycompetitors' from='competitorid' to='competitorid' visible='false' intersect='true'>"+
    "      <link-entity name='opportunity' from='opportunityid' to='opportunityid' alias='aa'>"+
    "        <filter type='and'>"+
    "          <condition attribute='opportunityid' operator='eq' value='" + entity + "'/>"+
    "        </filter>"+
    "      </link-entity>"+
    "    </link-entity>"+
    "  </entity>"+
    "</fetch>";
    
    var records = XrmServiceToolkit.Soap.Fetch(fetchXML);
    
    if (records.length < 2)
    {
    	//Stop the user from moving to next stage
    }

    You will also need to download and add this code to the opportunity form as well:

    xrmservicetoolkit.codeplex.com

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