D365 Get Current Record ID Using Javascript
To get the Current Record ID Using JavaScript.
Function getCurrentID(paramContext){
var formContext = paramContext.getFormContext();
var recordId1 = formContext.data.entity.getId();
var recordId2 = Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
console.log(recordId1);
console.log(recordId2);
}
In above Example you can use both ways to get the current record ID.
To get the current selected record ID from the Subgrid then :
Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”); will not return ID.
To get the Current Record Selected ID from Subgrid then Use:
var recordId1 = formContext.data.entity.getId();
// It will return ID of Current Selected Subgrid Record.
to replace the curly braces :
formContext.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
To get the Id of the record in JavaScript, let’s run the code below, which
Xrm.Page.data.entity.getId();
or by passing the formContext:
formContext.data.entity.getId();
And to remove the curly braces:
Xrm.Page.data.entity.getId().replace(“{“, “”).replace(“}”, “”);
Or
formContext.data.entity.getId().replace(“{“, “”).replace(“}”, “”);