web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Retrieve field value from lookup with Javascript

(0) ShareShare
ReportReport
Posted on by 35

Hi all,

unfortunately I am stuck with this code here.

From a Project I create a Case via a custom button (+ New Ticket - IT), it works fine.

I now need to add in my following Javascript, to lookup the account in this project and pass it to the case form

field "customerid", when Form is opening.

This goes beyond my knowledge of javascript at the moment, I am still learning.

function openItTicketForm (primaryControl) {

        var formContext = primaryControl;
     
        var recordGuid = formContext.data.entity.getId().replace("{", "").replace("}", "");
     
        var recordName = formContext.getAttribute("pde_name").getValue();
     
        var recordType = "pde_project";
     
        var entityFormOptions = {};
     
        entityFormOptions["entityName"] = "incident";
     
        entityFormOptions["openInNewWindow"] = true;

        entityFormOptions["formId"] = "3962b5bd-1ad2-ed11-a7c7-000d3adf75ee";

        // Set lookup column
     
        var formParameters = {};
     
     
        formParameters["skt_pde_project"] = [{ id: recordGuid, name: recordName, entityType: recordType }];
        formParameters["skt_requestto"] = 921720001;

        // Open the form.
     
        Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
     
            function (success) {
     
                console.log(success);
     
            },
     
            function (error) {
     
                console.log(error);
     
            });

           
         
     
     }
I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to replace line

    formParameters["skt_pde_project"] = [{ id: recordGuid, name: recordName, entityType: recordType }];

    with lines

    formParameters["skt_pde_project"] = recordGuid;

    formParameters["skt_pde_projectname"] = recordName;

  • smar.sus Profile Picture
    35 on at

    Thanks for your reply!

    Maybe I was not clear enough :) The above Code works fine. No need to change this.

    But I want to add to the above code following:

    The case form is linked to a project via a lookup, I want to retrieve the account from this project and prefill the Account field in the case form automatically as soon as the project is linked.

    2023_2D00_04_2D00_24-20_5F00_24_5F00_35_2D00_-Dynamics-365.png

  • Suggested answer
    RodRodriguez Profile Picture
    on at

    You want to lookup the account in the project and pass it to the case form field “customerid” when the form is opening. To do that, you need to use the Xrm.Page.getAttribute method to get the value of the account lookup field in the project form, and then use the Xrm.Page.getAttribute method again to set the value of the customerid lookup field in the case form. You also need to specify the id, name and entityType of the lookup value.

    Here is an example of how you can modify your code:

           var formContext = primaryControl;

           var recordGuid = formContext.data.entity.getId().replace("{", "").replace("}", "");

           var recordName = formContext.getAttribute("pde_name").getValue();

           var recordType = "pde_project";

           // Get the account lookup value from the project form

           var account = formContext.getAttribute("pde_account").getValue(); // change pde_account to your actual account lookup field name

           var entityFormOptions = {};

           entityFormOptions["entityName"] = "incident";

           entityFormOptions["openInNewWindow"] = true;

           entityFormOptions["formId"] = "3962b5bd-1ad2-ed11-a7c7-000d3adf75ee";

           // Set lookup column

           var formParameters = {};

           formParameters["skt_pde_project"] = [{ id: recordGuid, name: recordName, entityType: recordType }];

           formParameters["skt_requestto"] = 921720001;

           // Set the customerid lookup value to the account value

           formParameters["customerid"] = account; // make sure account is not null or undefined

           // Open the form.

           Xrm.Navigation.openForm(entityFormOptions, formParameters).then(

               function (success) {

                   console.log(success);

               },

               function (error) {

                   console.log(error);

               });

        }

  • smar.sus Profile Picture
    35 on at

    This worked perfectly ! so simple!

    Thank you so much

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 164 Super User 2026 Season 1

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 51 Most Valuable Professional

#3
NeerajPawar Profile Picture

NeerajPawar 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans