web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Check The Code for error free

(0) ShareShare
ReportReport
Posted on by 958

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

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    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
    55,410 Moderator 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 - MVP Profile Picture
    30,190 Moderator 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans