Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Remove the deprecated Xrm.Page.getAttribute function

(0) ShareShare
ReportReport
Posted on by 5

Hi All

  The company hopes to remove some functions that have been abandoned in the current version and replace them with the latest code .
But I noticed that use the executionContext.getFormContext() Instead of xrm.page.getgetAttribute method, I need to use executionContext as input parameter.
When I check the current JScript , I find the following code :

var sunRiseCo = sunRiseCo || {};
sunRiseCo.util = function () {

    var CACHE = {};

    function getAttr(attr) {
        var attrObj = Xrm.Page.getAttribute(attr);
        if (!attrObj) {
            var msg = 'miss attribute \'' + attr + '\' !';
            Xrm.Navigation.openAlertDialog(msg);
            throw new Error(msg);
        }
        return attrObj;
    }
    return {
        'attribute': {
            'get': getAttr

        }
    };

}();

At present, sunRiseCo.util.attribute.get()  is used in lots of pages , If i want to replace the Xrm.Page.getAttribute(attr) without change the input parameter of the getAttr() fuction, Is there any solution ?

  • Verified answer
    WMeschalin Profile Picture
    WMeschalin 75 on at
    RE: Remove the deprecated Xrm.Page.getAttribute function

    Hello BlueinLife,

    Effectively you will need to adjust the Function that is called on the form to statically assign formContext, something along the lines of:

    sunRiseCo.util = function () {
       var formContext;
       // This function is called via onLoad on the form
       function onLoad(executionContext) {
           formContext = executionContext.getFormContext();
       }
       function getAttr(attr) {
           var attrObj = formContext.getAttribute(attr);
           // etc. replace Xrm.Page with formContext from here.
       }
    }

    I hope this helped!

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! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans