Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Javascript for autofilling model-driven form

(0) ShareShare
ReportReport
Posted on by

Hi, hope this is the correct section for this post.  I am attempting use javascript to autofill items in my model-driven form.

So I have a column that is a lookup called job role and if users select a job, it will automatically go to another lookup column and select the role type for the user.

 

Job Role is a lookup column and Role is a second lookup to another column.  I attempted the below, but it is not filling out any items and when I delete an a selected job type I keep getting error: Cannot read properties of null (reading '0').

 

function autoPopulateRole(executionContext){    var formContext = executionContext.getFormContext();  formContext.ui.setFormNotification(/Testing v1/,/INFO/)    var selectedFunctionalRoleTypeRef = formContext.getAttribute(/jobrolelookup/).getValue()[0];    var Entity = selectedFunctionalRoleTypeRef.entityType;  var Id = selectedFunctionalRoleTypeRef.id  var Select = /?$select=roleLookup/;  var selectedJob = Xrm.WebApi.retrieveRecord(    Entity, Id, Select).then(      function success(result) {      console.log(/Success: / + result.roleLookup);      },      function (error) {          console.log(error.message);      });        var lookUpRole= selectedJob.roleLookup;            formContext.getAttribute(/joblookup/).setValue(lookUpRole);
 
 
Any help would be appreciated, thanks!
 
//
Sorry code snippet isn't formatting properly.
  • Suggested answer
    Haig Liu Profile Picture
    Microsoft Employee on at
    Javascript for autofilling model-driven form
    Hi Partner,
     
    It is recommended that you use the no-code program:
     
    Regarding the error you are experiencing, the possible causes are:
    1. Parameters are not initialized.
    2.Parameter does not exist
    3.Parameter format is incorrect
    I am not a professional developer, so my advice is limited.
     
    I hope this helps, but please let me know if you need anything else or if you have any other questions.
    thanks,
    Haig Liu

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... 293,998 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,850 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans