Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Using .OpenForm Won't fill out Custom Lookup

(0) ShareShare
ReportReport
Posted on by 55

Can't seem to get this open form function to fill out more than one lookup field? It fill out regarding, which was easy to do because i got that example from the API Documentation, but then when trying to use that same example to fill out a second lookup field it won't work.

Field is "Expense Category" with schema "d365pros_projectexpensecategory", code wise my understanding is you schemaid, schemaname, and schematype at the end of each field but that doesn't seem to do anything. 

Code below.

function OpenNewForm(id, name, ProjectExpID, ProjectExpName) {
    debugger
    //https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openform

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "d365pros_approvals";

    // Set default values for the Contact form
    var formParameters = {};
    //formParameters["new_field1"] = "Sample";
    //formParameters["new_field2"] = "Sample";

    // Set lookup column Regarding - THIS WORKS!
    formParameters["regardingobjectid"] = id; // ID of the user.
    formParameters["regardingobjectidname"] = name; // Name of the user.
    formParameters["regardingobjectidtype"] = "salesorder"; // Table name.

    //This Lookup Field Won't Wor Though?
    formParameters["d365pros_projectexpensecategoryid"] = ProjectExpID;
    formParameters["d365pros_projectexpensecategoryname"] = ProjectExpName; 
    //formParameters["d365pros_projectexpensecategorytype"] = "salesorderdetail"; 

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

}

Any help would be appreciated. 

  • jdaniel1 Profile Picture
    55 on at
    RE: Using .OpenForm Won't fill out Custom Lookup

    I think that was the trick. I swear i tried that before, but I tried that again actually just after I posted this XD and of course it works now. I removed the Type altogether; I think that helped as well. 

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Using .OpenForm Won't fill out Custom Lookup

    Hello,

    Try to use

    formParameters["d365pros_projectexpensecategory"] = ProjectExpID;

    formParameters["d365pros_projectexpensecategoryname"] = ProjectExpName;

    instead.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans