There are different ways to get the entity information from the form using JScript.
Let's say we need to get the information from within the form ribbon. We can get it with a simple statement as below,
var entityName=Xrm.Page.data.entity.getEntityName();
This will return the logical name of the entity for the record. For example, if the record is a contact this will return "contact".
If we need to get the entity name from the Homepage ribbon, then we have to do it in another way. Follow the below steps to achieve this,
- In the javascript add a parameter to accept this and pass the crmParameter "SelectedControlSelectedItemReferences"
- This will get us the below details, the JScript code would be like this.
function GetDetails(selectedControlSelectedItemRefernces)
{
var Id = selectedControlSelectedItemRefernces[0].Id;
var Name = selectedControlSelectedItemRefernces[0].Name;
var TypeCode = selectedControlSelectedItemRefernces[0].TypeCode;
var TypeName = selectedControlSelectedItemRefernces[0].TypeName;
}
If the user has selected multiple records in the grid then loop the "selectedControlSelectedItemRefernces" object and get the records one after the other.
If you are using ribbon editor you can refer to this blog for a step by step process how to achieve this.
Within the form if we need to get the Id of the record then it is a straight way process,
var recordId = Xrm.Page.data.entity.getId();
This will return a GUID value for the record.
No comments:
Post a Comment