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 365 | Integration, Dataverse...
Answered

List only the duplicate leads in a subgrid

(3) ShareShare
ReportReport
Posted on by 21
Hi,
 
I am not familiar with Js and I am trying to create view that displays duplicate Leads. I found this link Solved: List only the duplicate leads in a view on the community that addressed adding a subgrid on the Lead form to duplicate leads only when the firstname, lastname and topic is the same on the formOnload.
 
I tried the script but kept getting an error: 
One of the scripts for this record has caused an error. For more details, download the log file.
 
 
The script: 
 
function getDuplicates(executionContext) {
    var formContext = executionContext.getFormContext();
    if (formContext.ui.getFormType() != 1) {
        var duplicatesGridControl = formContext.getControl("Duplicates");
 
        if (duplicatesGridControl == null) {
            setTimeout(function () { getDuplicates(executionContext); }, 2000);
        } else {
            var leadId = formContext.data.entity.getId().replace("{", "").replace("}", "");
            var firstName = formContext.getAttribute('firstname')?.getValue();
            var lastName = formContext.getAttribute('lastname')?.getValue();
            var topic = formContext.getAttribute('subject')?.getValue();
 
            var fetchXml = `
                <fetch>
                    <entity name='lead'>
                        <attribute name='fullname'/>
                        <filter type='and'>
                            <condition attribute='firstname' operator='eq' value='${firstName}' />
                            <condition attribute='lastname' operator='eq' value='${lastName}' />
                            <condition attribute='subject' operator='eq' value='${topic}' />
                            <condition attribute='leadid' operator='ne' value='${leadId}' />
                        </filter>
                    </entity>
                </fetch>
            `;
 
            duplicatesGridControl.setFilterXml(fetchXml);
            duplicatesGridControl.refresh();
 
            var summaryObj = formContext.ui.tabs.get("Summary");
            var duplicatesObj = summaryObj.sections.get("Summary_Duplicates");
            duplicatesObj.setVisible(true);
        }
    }
}
 
 
The parameter is defined. so maybe i have it wrong. can anyone help? 
 
 
Thank you.
 
 
Categories:
I have the same question (0)
  • Suggested answer
    CU15040728-0 Profile Picture
    21 on at
    I figured it out, thanks.
  • Verified answer
    CU15040728-0 Profile Picture
    21 on at
    My mistake was manually adding the executionContext as the parameter.

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Pallavi Phade Profile Picture

Pallavi Phade 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans