Answered by:
CRM 2016 Javascript - Getting values from fields on parent account to populate matching fields on opportunity

Question
-
We have a series of fields on our account and opportunity fields that are lookups to the account entity. By default when you create these fields the system creates an automatic mapping from the field to the Accountid. This pulls the account name into this field on the opportunity when the record is created from the account. We would like to overwrite this value with the companion field that is on the account. IE if we have a associatedaccount field on the account that is a lookup to an account record and a associatedaccount field on the opportunity entity that is a lookup to an account record. We want the value that is in the account associatedaccount field to populate on the opportunity customer field. However what happens is the parent account name populates on the opportunity associatedaccount field rather than the account that is listed in the account associatedaccount field.
I am trying to find a way to write javascript on create of the opportunity form to pull the associatedaccount from the parent account via the relationship of customerid and populate on the opportunity form in the associatedaccount field. Any assistance would be greatly appreciated.
Jenn
- Edited by JenniferNHS Tuesday, October 18, 2016 8:16 PM
Tuesday, October 18, 2016 8:04 PM
Answers
-
Any success with resolving this issue?
- Marked as answer by JenniferNHS Thursday, May 18, 2017 3:30 AM
Tuesday, May 16, 2017 5:07 AM -
Thanks Faisal!
This however is more of an issue that if you have a Account Lookup field on the Account Form and have the same field on the Opportunity form it will be mapped by Dynamics to the Account name field. So if you create Opportunity from an Account it will populate all Account Lookup fields with the primary Account name. This system mapping can't be deleted and is automatically created by Dynamics.
The workaround is a synchronous workflow based on after create that will populate the field with the correct data or leave it blank if not populated on the Account form.
- Marked as answer by JenniferNHS Thursday, May 18, 2017 3:30 AM
Thursday, May 18, 2017 1:06 AM
All replies
-
Hi JenniferNHS,
By reviewing provided details, It looks you want to retrieve account details while creating opportunity from associated opportunity view for account using JavaScript.
In that case you can write a script on opportunity form (Quick Create) load event and check the form type is it “1” (for create). Since opportunity is associated with account there is account lookup which is already populated for opportunity, you can retrieve account details using WebApI request and populate for opportunity..
You can follow below link to know various form type.
https://msdynamicscrmblog.wordpress.com/2013/12/11/get-form-types-and-modes-in-dynamics-crm-2013/
Hope this helps.
Thanks!
Sam
Inogic | Blog | news@inogic.com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"- Proposed as answer by Mr. Santosh Bhagat Thursday, May 18, 2017 5:25 AM
Thursday, October 20, 2016 9:03 AM -
While this does help me get the potential account on the opportunity it does not allow me to get a field that resides on the account from through the relationship of the potential account so that I can populate a field on the opportunity. The field I need to populate is a lookup to the account however I do not want to bring the parent account down to this field I want to map it to another field. Since when you create a lookup field to the account it automatically creates the mapping I can not delete this mapping to create the custom one I want. Therefore I was going down the road of javascript but do not seem to be able to get this field through javascript.Monday, October 24, 2016 12:08 PM
-
Why not use the relationship to do what your are after.
In the relationship, mapping fields are identified, take this field from entity A and place it in this field in entity B.
So why not change the mapping.
Wednesday, October 26, 2016 12:00 PM -
Using the relationship was my first thought as well however since the field I am trying to map is a lookup to the account we just do not want the parent account to be filled in but rather a similar lookup field to the account from the account form when an opportunity is created. Mapping does not work here because there is already a system mapping established to this field for the parent account that can not be deleted or changed.Wednesday, October 26, 2016 12:07 PM
-
Any success with resolving this issue?
- Marked as answer by JenniferNHS Thursday, May 18, 2017 3:30 AM
Tuesday, May 16, 2017 5:07 AM -
Mapping only works on create of opportunity from Account. If Opportunity is created by populating Account lookup mapping will not work. I think you need a synchronous workflow to work on create of opportunity and on change of customer field to populate lookups in opportunity. You can do the same thing using JavaScript also however creating a workflow is easy.
Regards Faisal
Wednesday, May 17, 2017 8:35 AM -
Thanks Faisal!
This however is more of an issue that if you have a Account Lookup field on the Account Form and have the same field on the Opportunity form it will be mapped by Dynamics to the Account name field. So if you create Opportunity from an Account it will populate all Account Lookup fields with the primary Account name. This system mapping can't be deleted and is automatically created by Dynamics.
The workaround is a synchronous workflow based on after create that will populate the field with the correct data or leave it blank if not populated on the Account form.
- Marked as answer by JenniferNHS Thursday, May 18, 2017 3:30 AM
Thursday, May 18, 2017 1:06 AM -
We solved this by writing javascript to overwrite the fields where necessary.Thursday, May 18, 2017 3:30 AM
-
Interestingly however I have one Instance that respects the clear rule and a second one which doesn't both crm online same update.
WorkProcess:
If field contains data update lookup, Otherwise if field does not contain data set to clear lookup.
One does what it says the other instance will update the lookup but not clear it still populates it with the Primary account name.
Thursday, May 18, 2017 3:37 AM -
Go to customization select account then your lookup field. Delete unwanted mapping and add required mapping.
Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"
- Proposed as answer by Mr. Santosh Bhagat Thursday, May 18, 2017 5:25 AM
Thursday, May 18, 2017 5:25 AM -
If the fields are same then you can think of preview form of account on opportunity
Regards Faisal
Thursday, May 18, 2017 8:52 AM