Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Check The Code for error free

(0) ShareShare
ReportReport
Posted on by 932

function time() { var stdate = Xrm.Page.getAttribute("new_starttime").getValue(); var endate = Xrm.Page.getAttribute("new_finishtime").getValue(); if(stdate == null && endate == null) { alert(“Please enter the Start Time / Finish Time…”); return false; } else if(stdate==null) { alert(“Please enter the Start Time !”); return false; } else if(endate==null) { alert(“Please enter the Finish Time !”); return false; } var st=stdate.getTime(); var ed=endate.getTime(); var sdiff=(ed-st); var h=(sdiff/60/1000); var p=parseInt(h); var tm=p.toString(); Xrm.Page.getAttribute("new_timespent").setValue(tm); }

*This post is locked for comments

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Check The Code for error free

    You can also use http://jsbeautifier.org/ to format your code where you can see what is missing.

    Thanks

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Check The Code for error free

    Hi Shakti,

    It seems you have copied this code from somewhere. When you copy code, there are times when double quote syntax gets changed i.e. from “” to "".

    You can use the above validated code from Aric. Visual studio would be the best to test the syntaxt errora but if you do not have access then you can also use some online tools-

    esprima.org/.../validate.html

    http://jshint.com/

    They don't format your code so you may need to press enter after each line to correctly format it.

    Hope this help.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Check The Code for error free

    Copied your code above to Visual Studio.

    It seems like all of your quotes inside the alerts are not the correct type of quotes.

    Replace them:

    function time()

    {

       var stdate = Xrm.Page.getAttribute("new_starttime").getValue();

       var endate = Xrm.Page.getAttribute("new_finishtime").getValue();

       if(stdate == null && endate == null)

       {

           alert("Please enter the Start Time / Finish Time…");

           return false;

       }

       else if(stdate==null)

       {

           alert("Please enter the Start Time !");

           return false;

       }

       else if (endate==null)

       {

           alert("Please enter the Finish Time !");

           return false;

       }

       var st=stdate.getTime();

       var ed = endate.getTime();

       var sdiff = (ed - st);

       var h = (sdiff / 60 / 1000);

       var p = parseInt(h);

       var tm = p.toString();

       Xrm.Page.getAttribute("new_timespent").setValue(tm);

    }

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,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans