Hello All,
I am new to D365, currently I am trying to write a JS code to Auto populate a Company name Text field if the respective Company Name (Existing Client) is chosen in lookup by the user in the Custom entity. I can write this as a workflow but it happens only on Save. So I am looking to write JS code to achieve this change. So whenever users change the value in Existing Client Field then the respective company name should be populated from the Existing Client.
Can you kindly help here please?
Best Regards
Gowtham
Hi Gowtham89,
Please click Yes under "Did this answer your question?" to close this thread if the answer is helpful.
Thanks.
Hello, Thank you so much for the step by step explanation. I will try this out and will keep you posted once it is sorted out.
Hi Gowtham89,
You can use following js code into lookup field onChange event in form properties.
function getLookupName(executionContext) { var formContext = executionContext.getFormContext(); var lookupFieldObject = formContext.getAttribute("new_existingclient"); if (lookupFieldObject.getValue() != null) { var entityName = lookupFieldObject.getValue()[0].name; } var company = formContext.getAttribute("new_company"); company.setValue(entityName); }
Go Settings > Customizations > Customize the system > Web Resources to add new js resource.
Then expand Entities to open one form of the entity you need
Click 'Form Properties' to open dialog to add resource you just created.
Save and Publish all customizations.
Test:
Changing lookup field value without clicking save button, company field has been populated with lookup field name.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,524 Super User 2024 Season 2
Martin Dráb 228,493 Most Valuable Professional
nmaenpaa 101,148