Notifications
Announcements
No record found.
Hi,
Can anyone help me that how to get the id of the entity by using the javascript. As I'm using MS Dynamics CRM 2011
Thanks,
Kamyaka
*This post is locked for comments
If you are on the same form and want to get record id, you can use below code simply
Xrm.Page.data.entity.getId()
and if you are in another entity and want to get record id you need to use retrievemultiple query where you can define your condition and get data from that entity and can read record id.
Please download Ms CRM SDK you will see complete scripting reference there
Hi Mahender,
As I'm using the below code to get the entity id, Can you please help me as i'm not getting the entity id.
function GetRelated() {
var context = Xrm.Page.context;
var EntityID = Xrm.Page.data.entity.getId();
var serverUrl = context.getServerUrl();
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveResult = new XMLHttpRequest();
retrieveUserReq.open("GET", ODataPath + "/LeadSet(guid'" + EntityID + "')", true);
retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveResult.send();
if (retrieveResult.readyState == 4 /* complete */) {
if (retrieveResult.status == 200) {
var retrieved= this.parent.JSON.parse(retrieveResult.responseText).d;
var Result = retrieved.results[0];
alert(Result.LeadId.results[0].Line1);
window.open("xxxxxxxxxx" + Result.LeadId.results[0].DomainName, "_blank");
}
Kasani
Sorry for the above code please find the updated code
window.open("xxxxxxxxxx" + Result.LeadId.results[0], "_blank");
As I'm in the same form
As I said in my earlier reply, if you could explain what you are trying to do, we can help you will complete setups,
What you are trying to do here
alert(Result.LeadId.results[0].Line1); ??? what is line1 there is no field in lead with name of line1
if you have any custom field, you need to use below format
alert(Result.<<FieldSchemaname>>);
Share your requirement
if you are in the same form you will get it using your above code
why are you writing service call ??
As I'm trying to get the leadId in Url.
As I don't have any custom fileld.
I wrote the service call because on clicking the button it should open the window with url with LeadId.
I still don't understand if you are in lead form itself why you want to open the same form again using ribbon button, but if this is the only requirement you can simply write below code in your function that you can calling on ribbon button
var EntityID = Xrm.Page.data.entity.getId(); //get current record id
Xrm.Utility.openEntityForm("lead",EntityID); //open lead form with record id passed
As my requirement is on clicking the ribbon button on lead form it should open the window with fullname of the user and leadid of the particular lead which I have selected..
Now I'm getting the fullname of user and unable to retrieve the leadid
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2