Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Error replacing Xrm.Page with executionContext.getFormContext

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

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

    Hi, Leah Ju solution works perfectly, thanks!

  • Community Member Profile Picture
    Community Member Microsoft Employee 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.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,321 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

  • passaia Profile Picture
    passaia 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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,537 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,520 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans