Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

javascript

Posted on by Microsoft Employee

hi ,

i have a code where i intend to show a ShowLoadingAlert , refresh the page and hide the alert after process finish 

code is working fine in the first run however when i run it again it give me an error " TypeError: Cannot set property 'visibility' of undefined1 " 

note : main method is SetExcuteOnSaveComplete 

any support ? much appreciate

function ExecuteWhenSaveComplete(callback)
{
setTimeout(function ()
{
if (!Xrm.Page.data.entity.getIsDirty()) return callback();
//console.log('form not saved yet');
ExecuteWhenSaveComplete(callback);
}, 10000);
}

function SetExecuteOnSaveComplete()
{
alert("test")

showLoadingMessage("Loading...");
ExecuteWhenSaveComplete(function ()
{
console.log('form save complete');

HideLoadingMessage();

});

}

function showLoadingMessage(msg) {

try {
parent.document.getElementById('tdAreas').parentElement.style.display = 'none';
var newdiv = parent.document.createElement('div');
newdiv.setAttribute('id', 'msgDiv');
//newdiv.valign = 'middle';
newdiv.align = 'center';
newdiv.marginBottom = '5000px';
var divInnerHTML = "";
divInnerHTML += "";
divInnerHTML += "";
divInnerHTML += "";
divInnerHTML += "</br><img alt='' src='/_imgs/AdvFind/progress.gif' height='34px' width='34px'/></br>";
divInnerHTML += '<b>' + msg + '</b>';
divInnerHTML += "";
divInnerHTML += "";
newdiv.innerHTML = divInnerHTML;
newdiv.style.color = '#001D72 ';
newdiv.style.fontSize = '15px';
newdiv.style.zIndex = '1010';
newdiv.style.margin = '0 auto';
newdiv.style.marginTop = '210px';
newdiv.style.width = '300px';
newdiv.style.height = '135px';
newdiv.style.background = '#FFFFFF ';
newdiv.style.border = "thin solid #000000 ";

//newdiv.style.width = getBrowserWidth()+'px';
//newdiv.style.height = getBrowserHeight()+'px';
newdiv.style.position = 'relative';
parent.document.body.insertBefore(newdiv, parent.document.body.firstChild);

parent.document.getElementById('msgDiv').parentElement.style.visibility = 'visibile';


} catch (e) { alert(e) }
}



function HideLoadingMessage() {

try {


alert("LoadingHideMessage")
var msgdiv1 = parent.document.getElementById('msgDiv');
if(msgdiv1 != null && msgdiv1 != 'undefined')
{alert("msgdiv is not null")
parent.document.getElementById('tdAreas').parentElement.style.display = '';
parent.document.all.msgDiv.style.visibility = 'hidden';
}
} catch (e) { alert(e)}
}

*This post is locked for comments

  • Vahid Samimi Profile Picture
    Vahid Samimi 210 on at
    RE: javascript

    i used this tools and there was no bug.send your new code of this tool...

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: javascript

    use this new HideLoadingMessage function

    function HideLoadingMessage() {

    try {

    var fieldElement = document.getElementById("msgDiv");

    if (fieldElement!= null)

    {

    document.getElementById("msgDiv").style.visibility = "hidden";

    }

    else

    {

    parent.document.getElementById("msgDiv").style.visibility = "hidden";

    }

    parent.document.getElementById('tdAreas').parentElement.style.display = '';

    } catch (e) { alert(e)}

    }

  • Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: javascript

    Hi Hasooon,

    That's interesting because I have been experiencing this as well on some entities. I think I got around the issue by placing the alert.js at the top of the js files list so it gets loaded in first. Web development can be a real pain.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: javascript

    it is working fine but sometimes it need an additional refresh in the beginning to start ! then it works fine how many times i would like ! is it a bug ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: javascript

    actually this tools is not working i had to get another way and i did

    alertjs file installed and added to library but when i trying to use does no sense ? any idea about

  • Suggested answer
    Vahid Samimi Profile Picture
    Vahid Samimi 210 on at
    RE: javascript

    You can Use this tools :

    https://alertjs.codeplex.com/

    or

    https://notifyjs.codeplex.com/

    without any bug

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: javascript

    it was working as a first time but in the second run it doesn't

    i found it where i had to relace (   msgdiv1.parentNode.removeChild(msgdiv1 ); ) instead of (  parent.document.all.msgDiv.style.visibility = 'hidden'; )

    now it is working thanks for ur response thomas :)

  • Suggested answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: javascript

    Just taking a stab here, but is it because visible is spelled incorrectly?

    parent.document.getElementById('msgDiv').parentElement.style.visibility = 'visibile';

    Also have you tried debugging the code using F12 in the browser and placing breakpoints?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans