Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Xrm.page JavaScript update

(0) ShareShare
ReportReport
Posted on by 509

I'm going through our javascript code to remove depreciated JavaScript code and replacing where appropriate.

I have one piece of code which uses  Xrm.Page.data.entity.getId()

However as it's not called from a field change or load event, I'm not sure how to add the Execution Context to this.

Is there a way around this at all?


Thanks

  • Suggested answer
    Amit Prajapati Profile Picture
    Amit Prajapati 156 on at
    RE: Xrm.page JavaScript update

    Hi , You can use following code to retrive the Entity Id from the query string parameter which comes from the Global Content:

    var utility = parent.Xrm.Utility; // if using on HTML page

    var utility = Xrm.Utility; // if using on Entity form

    var globalContext = utility.getGlobalContext();

    var queryparameter = globalContext.getQueryStringParameters();

    var recordid= queryparameter.id.replace("{", "").replace("}", "");

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: Xrm.page JavaScript update

    Is there a quick and easy way I can find out what part of the ribbon accesses that JavaScript file?

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: Xrm.page JavaScript update

    cheers

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Xrm.page JavaScript update

    Oh, custom buttons, ok.  Here are some articles on passing in parameters, youll have to use the ribbon workbench - you can either install in or get to it from the XRMtoolbox.

    community.dynamics.com/.../getting-dynamics-365-formcontext-from-ribbon-workbench

    community.dynamics.com/.../how-to-pass-execution-context-as-a-parameter-in-ribbon-workbench

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: Xrm.page JavaScript update

    Code is

    (function() {

    Develop1_RibbonCommands_runDialogGrid = function(ids, objectTypeCode, dialogId) {

       if ((ids == null) || (!ids.length)) {

           alert(window.LOCID_ACTION_NOITEMSELECTED);

           return;

       }

       if (ids.length > 1) {

           alert(window.LOCID_GRID_TOO_MANY_RECORDS_IWF);

           return;

       }

       var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

       rundialog.get_query()['DialogId'] = dialogId;

       rundialog.get_query()['ObjectId'] = ids[0];

       rundialog.get_query()['EntityName'] = objectTypeCode;

       openStdWin(rundialog,buildWinName(null),615,480,null);

    }

    Develop1_RibbonCommands_runDialogForm = function(objectTypeCode, dialogId) {

       var primaryEntityId = Xrm.Page.data.entity.getId();

       var rundialog = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

       rundialog.get_query()['DialogId'] = dialogId;

       rundialog.get_query()['ObjectId'] = primaryEntityId;

       rundialog.get_query()['EntityName'] = objectTypeCode;

       var hostWindow = window;

           if (typeof(openStdWin) == 'undefined') {

               hostWindow = window.parent; // Support for Turbo-forms in CRM2015 Update 1

           }

           if (typeof(hostWindow.openStdWin) != 'undefined') {

               hostWindow.openStdWin(rundialog, hostWindow.buildWinName(null), 615, 480, null);

           }

    }

    })();

  • Lee-Martin Profile Picture
    Lee-Martin 509 on at
    RE: Xrm.page JavaScript update

    It's part of the ribbon (according to the description)- The problem is I can't see that it's being called from anywhere - I've not worked on the project until I've been asked to do this tidy up

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Xrm.page JavaScript update

    How/When is the code being called?  Or can you post your code so we can see it?

    You can always add this to it, then see if its working or not:

    formContext.data.entity.getId();

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans