web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Error replacing Xrm.Page with executionContext.getFormContext

(0) ShareShare
ReportReport
Posted on by 25

Hi,
I'm trying to replace the Xrm.Page collection in a script that fires on loading cases, in order to switch to the new Unified Interface. As documentation say, I enabled the flag to pass the execution context as the first parameter, and in the function I added the executionContext in input. I still can't retrieve the value of any of the case fields, the error I receive is "getAttribute is not a function"

The function code is the follow:


function form_onload(executionContext) {
var formContext = executionContext.getFormContext();
alert(formContext.getAttribute("incidentid").getValue());
}

I tried with this way too:

executionContext.getFormContext.ui.controls.get

but it still give me an error:Cannot read property 'controls' of undefined

Can someone help me please?

Thanks
Passaia

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hi,

    Can you try to replace incidentid with any other field which is available on the form like below I am getting ticket number field.

    function form_onload(executionContext) {

    var formContext = executionContext.getFormContext();

    alert(formContext.getAttribute("ticketnumber").getValue());

    }

    I don't think primary field of an entity will be available on the form.

    Please mark my answer verified if i were helpful

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hi passaia,

    If you want to get id od the current record, you need use following code:

    function getId(executionContext) {
        var formContext = executionContext.getFormContext();
    var incident= formContext.data.entity.getId().replace('{', '').replace('}', '');
    alert(incident);
    }

    Test:

    pastedimage1606112701964v1.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • passaia Profile Picture
    25 on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Thanks Leah Ju, it works!

    Just another question: can you tell me how I can get stageid field?

    I can't find it.

    Thanks

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hello,

    Are you talking about Active Stage Id from BPF? In this case following should work:

    var formContext = executionContext.getFormContext();
    var stageId = formContext.data.process.getActiveStage().getId();

    You can check following articles as references:

    docs.microsoft.com/.../getactivestage

    docs.microsoft.com/.../formcontext-data-process

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hi passaia,

    You can use following code to get stage id and stage name when you move next stage every time.

    And you just add the js to the form onload event.

    function formonload()
    {
    Xrm.Page.data.process.addOnStageChange(getStage); // Trigger the function when move to next stage.
    getStage();
    }
    
    function getStage()
    {
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageId = activeStage.getId();
    var stagename = activeStage.getName();
    alert("stageId is:"  stageId , "stagename is:"   stagename);
    }

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • Community Member Profile Picture
    on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hi Partner,

    Has the problem been solved? Any updates?

    Please click Yes under "Did this answer your question?" to close this thread.

    pastedimage1606380289940v1.png

    Thanks. 

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

  • passaia Profile Picture
    25 on at
    RE: Error replacing Xrm.Page with executionContext.getFormContext

    Hi, Leah Ju solution works perfectly, thanks!

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 76 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 55 Most Valuable Professional

#3
Anthony Blake Profile Picture

Anthony Blake 43 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans