Skip to main content

Notifications

Microsoft Dynamics CRM forum
Answered

How to write code to save the default lookup column in dynamics 365 form

Posted on by 100

Im trying the same code as mentioned my microsoft documnet openForm (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

But  i have a lookup column which is not a person type column then how can i give the default value?

formParameters["currencylookup"] = "Sample";

above is the lookup column i want to give default value , used the above code it doesnt work, the below code works only for text column and person type lookup column

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

// Set default values for the Contact form
var formParameters = {};
formParameters["subject"] = "Sample";
formParameters["description"] = "Default values for this record were set programmatically.";

// Set lookup column
formParameters["regardingobjectid"] = "3493e403-fc0c-eb11-a813-002248e258e0"; // ID of the user.
formParameters["regardingobjectidname"] = "Admin user"; // Name of the user.
formParameters["regardingobjectidtype"] = "systemuser"; // Table name.
// End of set lookup column

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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: How to write code to save the default lookup column in dynamics 365 form

    Hello,

    If the mentioned field is a lookup to currency you should use something like the following:

    formParameters["currencylookup"] = "Guid of the currency here";

    formParameters["currencylookupname"] = "US Dollars";//Place the currency name here

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans