Skip to main content

Notifications

Announcements

No record found.

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

On creation of Associate record set field lookup from subgrid related record in crm 365 using javascript

Posted on by 2,665

Hi All,

Below screen shots provided: Here while creating new technical activity attendance associated record i need to set lookup field  (campaign activity) & this campaign activity i need to take from the subgrid efficacy management subgrid view & record ID also need to set in Campaign Activity Id field using javascript.

Any link or code for this anyone ?

pastedimage1648620984951v1.png

pastedimage1648621007753v2.png

pastedimage1648621050505v3.png

Thanks,

Jharana

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: On creation of Associate record set field lookup from subgrid related record in crm 365 using javascript

    I have used below code its working fine.

    var req = new XMLHttpRequest();

                       req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/campaignactivities?$select=activityid,subject,_wcl_technicalactivity_value&$filter=_wcl_technicalactivity_value eq '" + newID + "'", true);

                       req.setRequestHeader("OData-MaxVersion", "4.0");

                       req.setRequestHeader("OData-Version", "4.0");

                       req.setRequestHeader("Accept", "application/json");

                       req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

                       req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

                       req.onreadystatechange = function () {

                           if (this.readyState === 4) {

                               req.onreadystatechange = null;

                               if (this.status === 200) {

                                   var results = JSON.parse(this.response);

                                   for (var i = 0; i < results.value.length; i++) {

                                       if (results.value[i]["activityid"] !== null)

                                           var activityid = results.value[i]["activityid"];

                                       if (results.value[i]["subject"] !== null)

                                           var subject = results.value[i]["subject"];

                                       if (results.value[i]["_wcl_technicalactivity_value"] !== null) {

                                           var _wcl_technicalactivity_value = results.value[i]["_wcl_technicalactivity_value"];

                                           var _wcl_technicalactivity_value_formatted = results.value[i]["_wcl_technicalactivity_value@OData.Community.Display.V1.FormattedValue"];

                                           var _wcl_technicalactivity_value_lookuplogicalname = results.value[i]["_wcl_technicalactivity_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

                                       }

                                       var value = new Array(); //create a new object array

                                       value[0] = new Object();

                                       value[0].id = activityid; // set ID to ID

                                       value[0].name = subject; //set name to name

                                       value[0].entityType = "campaignactivity"; // entity schema name

                                       if (formContext.getAttribute("wcl_catechnicalactivityattendanceid") !== null)

                                           formContext.getAttribute("wcl_catechnicalactivityattendanceid").setValue(value);

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: On creation of Associate record set field lookup from subgrid related record in crm 365 using javascript

    Hi,

    You should not use JS for your requirement because JS code will not get executed when you import record through excel.

    You should use either plugin/power automate to achieve your requirement.

    If you still want to use JS then you can use xrm.webapi client api to fetch record from subgrid -

    docs.microsoft.com/.../retrievemultiplerecords

    Set lookup - carldesouza.com/.../

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Jharana Baliyar Singh Profile Picture
    Jharana Baliyar Singh 2,665 on at
    RE: On creation of Associate record set field lookup from subgrid related record in crm 365 using javascript

    Hi Prashant,

    Thanks for your response. No its not like that only js but any approach will be fine if we are creating manually  the field should auto popilate with subgrid record guid.

    Actually in 2 way i need to add associated record ether through manually creation or excel upload from template.You can see below link which already i have posted regarding the query but thing is with name i am getting error.

    community.dynamics.com/.../lookup-field-value-import-through-excel-by-using-import-in-crm-365

    Thanks,

    Jharana

  • Prashnat Verma Profile Picture
    Prashnat Verma 287 on at
    RE: On creation of Associate record set field lookup from subgrid related record in crm 365 using javascript

    Hi Jharana,

    Is it a constraint that you can only use js to achieve this ?

    Thanks

    Prashant Verma

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans