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

Notifications

Announcements

No record found.

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.
I have the same question (0)
  • Suggested answer
    Haig Liu Profile Picture
    Microsoft Employee on at
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 45 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 36

#3
Satyam Prakash Profile Picture

Satyam Prakash 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans