Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Setting the regarding field on load with Javascript

(0) ShareShare
ReportReport
Posted on by 2,115

Hi all,

I'm having issues with the set regarding field. I'm using the navigateto javascript method to open a dialogue box for a task activity when updating a case field. The I've console logged the id, Name and entityType and they are all correct but it keeps saying I've got a script error.

My question is: is it possible to update a regarding lookup field? I keep reading that it's not possible?

Below is my code:

function onloadRegarding(executionContext) {
    var formContext = executionContext.getFormContext();

    var caseIdPassed = formContext.data.attributes.get("case_id").getValue().slice(1,-1);
    var caseName = formContext.data.attributes.get("case_name").getValue();


    var caseLookup = new Array ();
    caseLookup[0] = new Object ();
    caseLookup[0].id = caseIdPassed;
    caseLookup[0].name = caseName;
    caseLookup[0].entityType = 'incident';

    formContext.getAttribute("regardingobjectid").setValue(caseLookup);
    
}

I've tried for the field name both regardingobjectid and just regarding but I keep getting a script error in UI which doesn't tell me anything.

Any help would be greatly appreciated.

  • MikeC282 Profile Picture
    2,115 on at
    RE: Setting the regarding field on load with Javascript

    Thanks guys for your suggestions. I also managed to fix it myself. I had a brain fart moment and forgot to pass the executionContext as the first parameter. Thanks for all your suggestions.

  • Verified answer
    TNS Profile Picture
    1,197 on at
    RE: Setting the regarding field on load with Javascript

    Hi,

    If you want to open a task activity form and set regarding field, from another entity you can use below code:

    function onsave(context)

    {

    var formContext = context.getFormContext();

    //Entity to open

    var entityFormOptions = {};

    entityFormOptions["entityName"] = "task";

     // Form parameters:

     recordId = formContext.data.entity.getId();

     recordEntityName = formContext.data.entity.getEntityName();

     recordName = formContext.getAttribute("fullname").getValue();

     var regardingValue = new Array();

     regardingValue[0] = new Object();

     regardingValue[0].id = recordId;

     regardingValue[0].name = recordName;

     regardingValue[0].entityType = recordEntityName;

     var formParameters = {};

     formParameters["regardingobjectid"] = regardingValue;

     Xrm.Navigation.openForm(entityFormOptions, formParameters).then(

       function (success) {

           console.log(success);

       },

       function (error) {

           console.log(error);

       });

    }

    Regards,

    TNS

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Setting the regarding field on load with Javascript

    Hi partner,

    1.This code "caseLookup[0 = new Object ();" is not necessary which may cause the problem.

    Please change your code about setting value to regarding as following.

        var caseLookup = new Array ();
        var regardingItem = new Object ();
        regardingItem.id = caseIdPassed;
        regardingItem.name = caseName;
        regardingItem.entityType = 'incident';
        caseLookup[0]=regardingItem;

    2.You could also use web api to update regarding field.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/updaterecord

    pastedimage1590999123920v1.png

    Best Regards,

    Leo

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,991 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans