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 :
Microsoft Dynamics CRM (Archived)

CRM javascript to find field value of an enity by passing id?

(0) ShareShare
ReportReport
Posted on by

Hi All,

          I have an entity named Item . Item having field named as current stock, which will be updated on  purchasing .

I want to get the current stock value by passing the item id from the look up(on change of item look up).Please give me some samples.

I am new to CRM

*This post is locked for comments

I have the same question (0)
  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi Nidhin,

    Why should you pass the item id for getting the current stock value?

  • Suggested answer
    AbiRami Profile Picture
    516 on at

    Hi Nidhin,

    Do u want current stock value in another entity or in the same entity?

  • Community Member Profile Picture
    on at

    I need to show the current stock in Purchase entity. The purchase entity form have the look up of Item enity.  

  • Verified answer
    AbiRami Profile Picture
    516 on at

    Then u can retrieve the field values from Item entity using the lookup value in purchase entity. Refer the following link.

    arvindcsit.wordpress.com/.../retrieve-related-entitys-field-value-from-client-side-using-odata

    Thanks

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Nidhin,

    Please refer the following community thread. it helps you a lot to retrieve data of one entity to another entity using JavaScript.

    community.dynamics.com/.../139190

  • Verified answer
    JohnAnonymous Profile Picture
    5,241 on at

    To do this you need to do the following:

    1. Get the id of the item lookup value on your current form.
    2. De a query via the WebApi to retreive the value from the item entity
    3. Use that value in the way you need to

    For both 1 and 2 there are a lot of resources available with examples. If you are not experienced with REST, I would advise you to use the CRM Rest Builder github.com/.../CRMRESTBuilder

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    You could try the following code.

    function GetCurrentStockValue() {
        //Get the details of item record associated with the purchase record
        var EntityName, EntityId, LookupFieldObject;
        var resultXml;
    //Retrieve the item lookup id in purchase record LookupFieldObject = Xrm.Page.data.entity.attributes.get('itemid'); if (LookupFieldObject.getValue() != null) { EntityId = LookupFieldObject.getValue()[0].id; EntityName = LookupFieldObject.getValue()[0].entityType; resultXml = getDetails(EntityName, EntityId); } //Check if field Value Contains or Not if (resultXml != null && resultXml.attributes['currentstock'] != null) { //Fetching the field from item record associated with the purchase record var currentstock = resultXml.attributes['currentstock'].value; // Setting the value of current stock depending on the item selected in the purchase record Xrm.Page.getAttribute("currentstock").setValue(currentstock); } } //Get the details of a record by entity name and entity id function getDetails(EntityName, EntityId) { var cols = ["currentstock"]; var retrievedResult = XrmServiceToolkit.Soap.Retrieve(EntityName, EntityId, cols); return retrievedResult; }
  • Community Member Profile Picture
    on at

    Its done thanks Nithya and all others for your 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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans