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

How to return value from a WebResource ?

(0) ShareShare
ReportReport
Posted on by 95

Hello Everyone,

I'm using the following code to open a web resource and update some data based on user activity.

Xrm.Navigation.openWebResource(webResourceModal, windowOptions, data)

function successCallback(returnValue) {
          // do stuff
}


Upon closing the modal, I need to return some values to the calling script and reload the page. How do i trigger the successCallback function from the modal ?

Can anybody help me with this ? Thanks in advance.

I have the same question (0)
  • Suggested answer
    Marco.P Profile Picture
    2,405 on at

    In your web resource try adding a window.returnValue=yourvalue; and handle It in the success callback.

    Hope it helps,

    Marco

  • cloflyMao Profile Picture
    25,210 on at

    Hi muttakin,

    If you are working with online version, then you could use Xrm.Navigation.navigateTo to open web resource, it is easy to execute custom function in its successCallback(upon closing the modal) function. 

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/navigateto#example-4-open-an-html-web-resource-in-a-dialog

    Regards,

    Clofly

  • muttakin Profile Picture
    95 on at

    Hello Clofly,

    I have tried to use Xrm.Navigation.navigateTo first. But it was not working. Then i find out that Xrm.Navigation.navigateTo only works in Unified interface but we are using Legacy Web Client for CRM. So i had to use Xrm.Navigation.openWebResource which does not have any callback attribute.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi muttakin,

    Are you actually using Dynamics CRM 2016? Because I see you added it as tag for your question.

    I didn't find a supported way to call successCallback function by using Xrm.Navigation.navigateTo.

    You could try unsupported way to open your web resource and then run custom function before popup window closes.

    https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript

    And if CRM 2016 is your current environment, also check whether Xrm.Internal.openDialog or Xrm.Utility.openDialog still works.

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/260526/xrm-internal-opendialog-with-parameters

    https://butenko.pro/2017/11/21/microsoft-dynamics-365-v9-0-whats-new-in-clientside-for-devs-besides-xrm-webapi/

    If you are using online version, please migrate to UCI, the Legacy Web Client will be deprecated on Oct.

    Regards,

    Clofly

  • muttakin Profile Picture
    95 on at

    Hello Marco,

    Since Xrm.Navigation.openWebResource doesn't have any successCallback attribute, how do I trigger the successCallback function when the modal closes ?

  • Suggested answer
    muttakin Profile Picture
    95 on at

    Thank you everyone for the help. I ended up using Window.open(). I didn't have to return any value to the parent, as I reload the page to see the changes. To solve my problem I've used the following code.

    const url = "webResourceModal?Data=" + encodeURI(JSON.stringify(dataParam));

    const windowName = "webResourceWindow";

    const windowFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=800, height= 900";

    const myModal = window.open(url, windowName, windowFeatures);

    //successCallBack

    myModal.onbeforeunload = () => {

       //to reload page

       Xrm.Utility.openEntityForm("EntityName", Id);

    };

  • cloflyMao Profile Picture
    25,210 on at

    Hi muttakin,

    It is very glad that your problem has been solved.

    Regards,

    Clofly

    Please kindly mark as verified if you had found any answer helped, it would be really appreciated.

    Regards,

    Clofly

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 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans