Hello,
is there a (not custom code) way to pass the values of an existing entity record to a new lookup form?
Case:
In the entity salesorder exists this lookup to the entity sc-data
Problem:
If the user clicks on "Neu" (New) it should automatically fill-out some fields that are already filled out in the salesorder.
My ideas:
- If possible: Get parent id from the Xrm context and retrieve the data. Then use Xrm setValue.
- Create a custom button and HTML
- Using Business process flow (I could not achive it with that. Since I could not create an entity with it or pass parameters to the workflow that should create the new entity.)
- Field mappings. It seems like that it did not work, because it is a N:1 relationship.
Any suggestions?
Ok, I've found it. You can retrieve the data from the context by using this.
window.top.opener.Xrm.Page.data.entity.attributes.get("customerid").getValue()
I think this will be my solution to go. Thanks again for your help.
EDIT: The full code looks like this
if (Xrm.Page.ui.getFormType() == 1) // 1 = create { // Get the value of the parent window let parentCustomerRef = window.top.opener.Xrm.Page.data.entity.attributes.get("customerid").getValue(); // Set the value in the new opened form Xrm.Page.getAttribute("wd_customer").setValue(parentCustomerRef); }
Hi Matt,
thanks for your answer. No, it doesn't get saved. (Auto-saving is disabled.)
I was hoping for a solution without a custom code, but as it looks this is not possible. I don't understand why the field mapping did not work for both directions.
Also thanks for your suggestion with the JS logic. I was hoping for a way to get the data out of the context like in a plugin, but this is also a nice idea.
Please give me some time to try it out and I will response to you after that or mark your answer als solution.
Best regards,
Bernhard
Her Bernhard,
When you click "New" and create a new record, does that record get saved and automatically set in the source record lookup field?
The reason I ask is because I tested with one of my environments, and on click "New" the URL of the new window has some parameters that could be used by you to get what you need. In this case, my parameters looked like (with some other information):
extraqs=%3f_CreateFromId%3d%257bCB63BECB-C3BF-E811-80DA-005056A46CE5%257d%26_CreateFromType%3d10510%26
You could write Javascript that would run OnLoad of the sc-data entity, parse out the extraqs parameter, get the "CreateFromId" key-value, and use that to retrieve the record (which should be source salesorder in your case) and any associated fields you would like. From there, you would then set the field values on the sc-data form with those retrieved from the query.
This is essentially what you posed as your first item. Depending on your version of CRM, you could utilize the asynchronous Web API call to retrieve the data, and when it's done, set the fields. If the version does not have that, then you can use the standard XMLHttpRequest way of retrieving the data, but would still recommend running it asynchronously since this is the best practice.
If you have more questions just let me know!
Thanks!
Matt Bayes
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Eugen Podkorytov
106
Muhammad Shahzad Sh...
106
Most Valuable Professional