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 :
Customer experience | Sales, Customer Insights,...
Answered

How to add connection to subgrid

(0) ShareShare
ReportReport
Posted on by 80

Hello dear fellas,

I need to write a script that would add the opportunity owner to sales team subgrid, i`ve been looking aroung and didn`t find anything on how to do it, please help.

Here is the code I`ve written:

function SetOpportunityOwnerAsSalesMember(executionContext) {

var formContext = executionContext.getFormContext();
if (formContext == null) {
formContext = Xrm.Page;
}
var userName = formContext.getAttribute("ownerid").getValue()[0].name;
var salesTeamGridContext = formContext.getControl("SalesTeam");


if (!IsUserExistsInSalesTeam(userName, salesTeamGridContext)) {
AddUserToSalesTeam(userName)
}


}

function IsUserExistsInSalesTeam(userName, gridContext) {
var result = false;
var gridRows = gridContext.getGrid().getRows();

gridRows.forEach(element => {

var salesTeamMemberName = element.getData().getEntity().getEntityReference().name

if (salesTeamMemberName.length > 0 && userName == salesTeamMemberName) {
result = true;
}
})

return result;
}

function AddUserToSalesTeam(user) {
//
console.log("added user to sales team")
}

Best regards,

Bohdan

I have the same question (0)
  • Suggested answer
    Inogic Profile Picture
    703 on at
    Hi Bohdan,

    We assume that you want to create a connection record of Opportunity Owner with the Opportunity record including the Sales Team role.

    We advise you to use Xrm.WebApi.createRecord(entityLogicalName, data).then(successCallback, errorCallback) method to create a connection record.

    Prerequisite for creating a connection record is to add record1 (opportunity) and record2 (user) lookup data including record2 role in an object which will be passed in create record method as shown in below code.

    var data = {}
    data["record1id_opportunity@odata.bind"] = "/opportunities(" + OpportunityGuid + ")";
    data["record2id_systemuser@odata.bind"] = "/systemusers(" + UserGuid + ")";
    data["record2roleid@odata.bind"] = "/connectionroles(" + SelectedRoleGuid + ")";
    Xrm.WebApi.createRecord(“connection”, data).then((result)=>{},(error)=>{});
     
    For reference please follow the link provided here.
     
    Hope this helps!

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans