Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Passing record from main form to related Child on Quick Create Form

Posted on by 160

Hi All,

I Have a look up field in Account form which name is new_country and the same field on Qucik create form of Contact. I want pass thes record from Main form of Contact to contact Quick create Form:

pastedimage1598817058703v2.png

I have used this below code and add it to quick Create form in Contact (On Load):

function SetLocalStorage(executionContext){
    var formContext = executionContext.getFormContext();
    var country = formContext.getControl("New_country").getAttribute().getValue().toString();
    localStorage.setItem("Country",country);
}

and this below code on field of Country (onChange) in Account main form:

function RetrieveStorageValue(executionContext){

    var formContext = executionContext.getFormContext();
    var country = localStorage.getItem("Country");
    formContext.getAttribute("New_address1country").setValue(country);
    localStorage.removeItem("Country");
}

I recieved an Error: Cannot read property 'setValue' of null 

Does anybody have any idea?

Thank you in advance

Regrads

  • Verified answer
    RE: Passing record from main form to related Child on Quick Create Form

    Hello Elpibato,

    I also found the similar request within this forum and as Andrew also mentioned, you can try to use mappings.

    Please see following URL:

    - community.dynamics.com/.../291929

    Further, as an alternative, you can also try to use the operation completely by code, using similar to the previous known function "openQuickCreate". Please note, this function is already marked as deprecated and replaced by Xrm.Navigation.openForm:

    - docs.microsoft.com/.../jj602956(v=crm.8)

    - docs.microsoft.com/.../xrm-utility

    - docs.microsoft.com/.../openform

    Best regards

  • Suggested answer
    thonda Profile Picture
    thonda on at
    RE: Passing record from main form to related Child on Quick Create Form

    Hi Elpibato,

    Please use JSON.Stringify to save the value in local storage and then use JSON.Parse to reconstruct the object after retrieving from the local storage.

    Here is a blog that explains the same carldesouza.com/.../

    Also you must ensure that an array is passed as value to setValue of lookup field, the first element in the array is expected to be the object that represents the selected value.

    So whatever you do with storage , finally this structural requirement should be met while assigning values to lookup field

    community.dynamics.com/.../how-to-get-and-set-a-lookup-field-using-javascript-in-dynamics-365

    Also Andrew pointed out take care of case sensitivity of field names. Let me know if you have any further questions otherwise please mark it as an answer.

    Regards,

    Praveen T

    D365 Customization Support

    Microsoft Corportation

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Passing record from main form to related Child on Quick Create Form

    Hello,

    The main reason why your code doesn't work is because you should use all field names in lowercase - new_country, not New_country and new_address1country, not New_address1country.

    Anyway there is no need to write any code because you can use mapping to pass that field - www.marksgroup.net/.../

  • Suggested answer
    thonda Profile Picture
    thonda on at
    RE: Passing record from main form to related Child on Quick Create Form

    Hi Elpibato,

    Please use JSON.Stringify to save the value in local storage and then use JSON.Parse to reconstruct the object after retrieving from the local storage.

    Here is a blog that explains the same carldesouza.com/.../

    Also you must ensure that an array is passed as value to setValue of lookup field, the first element in the array is expected to be the object that represents the selected value.

    So whatever you do with storage , finally this structural requirement should be met while assigning values to lookup field

    community.dynamics.com/.../how-to-get-and-set-a-lookup-field-using-javascript-in-dynamics-365

    Also Andrew pointed out take care of case sensitivity of field names.

    Regards,

    Praveen T

    D365 Customization Support

    Microsoft Corportation

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans