Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

TypeError: Cannot read properties of null (reading 'getParent')

$
0
0

Hi,

I am trying to add an onChange event on Dynamics 365 to change the background color of statecode field when an oportunity is Open, Won or Lost.

I am getting "TypeError: Cannot read properties of null (reading 'getParent')" when using this JS code:

-----

function onChangeStateCode() {
    var statecodeField = Xrm.Page.getAttribute("statecode");
    var statecodeValue = statecodeField.getValue();
    var statecodeControl = Xrm.Page.getControl("statecode");

 

    var backgroundColor = "";
    if (statecodeValue === 0) { // 0 represents the Open state
        backgroundColor = "#ffffcc"; // Yellow
    } else if (statecodeValue === 1) { // 1 represents the Won state
        backgroundColor = "#ccffcc"; // Light Green
    } else if (statecodeValue === 2) { // 2 represents the Loss state
        backgroundColor = "#ffcccc"; // Light Red
    } else {
        backgroundColor = "#ffffff"; // White
    }

 

    statecodeControl.getParent().style.backgroundColor = backgroundColor;
}

 

// Register the onChange event handler for the statecode field
Xrm.Page.getAttribute("statecode").addOnChange(onChangeStateCode);

-----

Thank you,

Tomas Cossara


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images