web
You’re offline. This is a read only version of the page.
close
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,175

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.

I have the same question (0)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    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

  • Verified answer
    TNS Profile Picture
    1,197 on at

    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

  • MikeC282 Profile Picture
    2,175 on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans