Open View as Dialog using command button and send update data from Dialog view using command button navigateTO
Step 1 : open a view as dialog from subgrid command
use below code on command button on form.
JavaScript
function CreateTicket(primaryControl)
{
sessionStorage.setItem("cid", primaryControl.data.entity.getId().replace("{","").replace("}",""));
var pageInput = {
pageType: "entitylist",
entityName: "sanjay_sanjayhdfcserviceticket"
};
var navigationOptions = {
target: 2,
height: {value: 80, unit:"%"},
width: {value: 70, unit:"%"},
position: 1
};
Xrm.Navigation.navigateTo(pageInput,navigationOptions).then(
function success() {
// Run code on success
},
function error() {
// Handle errors
}
);
}
JavaScriptStep 2 : Call script on home grid command button on the dialog entity view
use below code.
JavaScript
async function AddTicket(Ids) {
var recCount=0;
var selectedRecs = String(Ids).split(",");
var cid = (sessionStorage.getItem("cid"));
for (let index = 0; index < selectedRecs.length; index++) {
const element = selectedRecs[index];
// define the data to update a record
var data =
{
"sanjay_TargetCustomer_contact@odata.bind": "/contacts("+cid+")"
}
// update the record
await Xrm.WebApi.updateRecord("sanjay_sanjayhdfcserviceticket", selectedRecs[index], data).then(
function success(result) {
recCount = recCount+1;
// perform operations on record update
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
}
alert(recCount + " records are linked.");
var pageInput = {
pageType: "entityrecord",
entityName: "contact",
entityId:cid
};
var navigationOptions = {
target: 1,
height: {value: 90, unit:"%"},
width: {value: 70, unit:"%"},
position: 1
};
Xrm.Navigation.navigateTo(pageInput,navigationOptions).then(
function success() {
// Run code on success
},
function error() {
// Handle errors
}
);
}
JavaScriptHope this helps.