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

Announcements

No record found.

News and Announcements icon
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

  • Suggested answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    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

    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

    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

    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

    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

    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

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
ParthPatel249 Profile Picture

ParthPatel249 62

#2
11manish Profile Picture

11manish 48 Super User 2026 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 40 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans