Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Redirect in dynamics 365

Posted on by 1,075

Hello Community Experts,

If i click the record link present in one of the tab, it opens a form related to that record, I'll perform necessary changes to the data of that form. Once i hit save, it stays in same form after saving.

The actual requirement is, if i click save, it should come back to the same tab from where the link was opened.

I'm struggling a lot with this

Kindly guide,

Best Regards,

Sumaira Noor

  • Sumaira Noor Profile Picture
    Sumaira Noor 1,075 on at
    RE: Redirect in dynamics 365

    Thanks a lot for the guidance Mehdi

    I tried but still they wanted me to look into it

    I'll suggest them again

    Best Regards,

    Sumaira Noor

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Redirect in dynamics 365

    Hi,

    Sorry, I didn't test my code. I did some correction, now it works.

    function onLoad(executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.data.entity.addOnSave(CloseFormAfterSave);
    }
    
    function CloseFormAfterSave(executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.ui.close();
    }

    Register the first function called "onLoad" in Onload event, and pass the executionContext as a parameter.

    Don't forget to remove the second function from OnSave Event.

    Please, you don't need this kind of customization, users can use easily the OOB "Save & Close" button.

  • Sumaira Noor Profile Picture
    Sumaira Noor 1,075 on at
    RE: Redirect in dynamics 365

    Thanks a lot for the response again Mehdi

    Its throwing new error now, and its not getting saved also

    ErrSavePNG.PNG

    Kindly guide,

    Best Regards,

    Sumaira Noor

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Redirect in dynamics 365

    Don't forget to pass the executionContext as parameter.

    docs.microsoft.com/.../clientapi-execution-context

    2273.clientapi_2D00_passexecutioncontext.png

  • Sumaira Noor Profile Picture
    Sumaira Noor 1,075 on at
    RE: Redirect in dynamics 365

    Thanks for the quick response Mehdi, Its throwing this error on form save

    Cannot read property 'getFormContext' of undefined

    Err21.PNG

    Kindly guide,

    Best Regards,

    Sumaira Noor

  • Verified answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Redirect in dynamics 365

    Hi, 

    you can use  formContext.ui.close(); Check this sample code: 

    function CloseFormAfterSave(executionContext) {
        var formContext = executionContext.getFormContext();
        formContext.data.save().then(function successCallback() {
            formContext.ui.close();
        });
    }

    Register your function in OnSave Event in the opened form. Hope this helps. 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans