Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to set the CustomerID lookup field on case form from Javascript?

Posted on by Microsoft Employee

Hello, 

I want to update the CustomerId lookup field on Case form by the value I select in the primarycontact field. I am able to get the id of the record on the primarycontact field from JS, but the customerid field is not populating properly using the Business Rule. How can that be done using JS?

Thanks, 

Fahad

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set the CustomerID lookup field on case form from Javascript?

    Hi Guys,

    Thanks for the help. Yes CustomerId is a but tricky.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to set the CustomerID lookup field on case form from Javascript?

    Hi Fahad,

    Mansoor is correct , CusttomerID field in case form support both Account and Contact type of customer . You can see when you lookup more records in the lookup entity you can select both contact or account type of entity. So when you are going to set customer using javascript  like other lookup it will not work as you need to pass entity type as well otherwise lookup  will not identity which type of customer you are going to set.

    //Set Customer
    SetCustomer("{51B6C014-D002-E711-8102-000C29CBC14A}", "FAHAD", "contact")  // pass "account" for account type of customer
    
    // You need to pass CustomerId ,CustomerName and CustomerType (account,contact)
    function SetCustomer(CustomerId, CustomerName, CustomerType) {
        var lookup = new Array();
        lookup[0] = new Object();
        lookup[0].id = CustomerId; // GUID of customer 
        lookup[0].name = CustomerName;   // Nmae of customer
        lookup[0].entityType = CustomerType; // Customer Type - account or contact 
        Xrm.Page.getAttribute("customerid").setValue(lookup);  
    }
    

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set the CustomerID lookup field on case form from Javascript?

    Customer field in case bit tricky. Based on object type you can set lookup fields as below.

    var object = new Array();

    object[0] = new Object();

    object[0].id = fieldId;

    object[0].name = value;

    object[0].entityType = fieldType;  // account or contact

    Xrm.Page.getAttribute("yourfieldname").setValue(object);

    Mansoor

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans