Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

javaScript error

  • 1.  javaScript error

    GOLD CONTRIBUTOR
    Posted Jun 03, 2021 04:51 PM
    I want to update a date field on an Opportunity form when an option field changes.  Here is my code:

    function FieldValueChange(){
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(Date.now());
    }

    I'm getting this error when I select an option:

    The option field is called pwl_weighted is the field that triggers the code (OnChange event) and the date field (pwl_wtmodified) is what should be modified.

    Any ideas as to what I am doing wrong?

    Thanks.

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------


  • 2.  RE: javaScript error

    GOLD CONTRIBUTOR
    Posted Jun 04, 2021 02:49 AM

    Hi Karen,
    date.now() won't work (as you've encountered). It's better to create a variable like:
    var date = new Date();
    and then change your code to
    function FieldValueChange(){
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(date);
    }

    another way you could make this work, is with a real-time workflow. That will only kick in on save of course, which might be the reason you're going for javascript.

    hope this helps you.



    ------------------------------
    Rogier Vriezen
    MS Cloud Consultant
    Amsterdam, Netherlands
    ------------------------------



  • 3.  RE: javaScript error

    GOLD CONTRIBUTOR
    Posted Jun 04, 2021 08:15 AM
    Hi Rogier...I appreciate your reply and assistance.

    I made the change as you suggested.  It now reads:
    function FieldValueChange(){
    var date = new Date();
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(Date);
    }

    I'm still getting the same error.  I'm using JavaScript because I will be calculating the number of days the field "pwl_weighted" has been in a "stage." (values are 10%, 25%, etc) and using that variable to update some calculated textboxes.  I'd like these calculations to be visible before save.

    Thanks again,

    Karen



    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------



  • 4.  RE: javaScript error

    TOP CONTRIBUTOR
    Posted Jun 04, 2021 08:12 AM

    Try changing you setValue parameter to new Date().  That should return a datetime value with the current timestamp.


    Glen Wolinsky
    IT Application Developer

    LinkedIn
    Facebook
    Twitter
    Instagram
    (423) 785-8363
    f(423) 321-1682
    Volunteer Building Suite 1200 | 832 Georgia Avenue | Chattanooga, TN 37402
    CONFIDENTIALITY NOTICE
    The information contained in this e-mail message is legally privileged and confidential, and is intended only for the use of the addressee. If you are not the intended recipient, please be aware that any dissemination, distribution or copy of this e-mail is prohibited. If you have received this e-mail in error, please immediately notify us by reply e-mail and delete this message and any attachments. Thank you.





  • 5.  RE: javaScript error

    GOLD CONTRIBUTOR
    Posted Jun 04, 2021 08:19 AM
    Hi Glen - thank you so much for your reply.  Here is my new code...is this what you mean?

    function FieldValueChange(){
    var date = new Date();
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(date);
    }

    I'm still getting the same error.  I've been known to make simplistic, stupid mistakes - so I won't be surprised if this is one of them!  lol

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------



  • 6.  RE: javaScript error

    TOP CONTRIBUTOR
    Posted Jun 04, 2021 08:27 AM

    Yes.  You could also just code:   Xrm.Page.getAttribute("pwl_wtmodified").setValue(new Date());

     

    Unless you need the variable later in your code.

     

     

    Glen Wolinsky
    IT Application Developer
    LinkedIn
    Facebook
    Twitter
    Instagram
    (423) 785-8363
    f(423) 321-1682
    Volunteer Building Suite 1200 | 832 Georgia Avenue | Chattanooga, TN 37402

     

    CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

     

    Hi Glen - thank you so much for your reply.  Here is my new code...is this what you mean? function FieldValueChange(){ var date = new Date(); Xrm...

    Dynamics 365 User Group

    Customer Engagement & Dynamics CRM Forum

    Post New Message

     

    Re: javaScript error

    Karen Bebow

    Jun 4, 2021 8:19 AM

    Karen Bebow

    Hi Glen - thank you so much for your reply.  Here is my new code...is this what you mean?

    function FieldValueChange(){
    var date = new Date();
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(date);
    }

    I'm still getting the same error.  I've been known to make simplistic, stupid mistakes - so I won't be surprised if this is one of them!  lol

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------

      Reply to Group via Email   View Thread   Recommend   Forward   Flag as Inappropriate  


    Try changing you setValue parameter to new Date().  That should return a datetime value with the current timestamp.

    Glen Wolinsky

    IT Application Developer

    LinkedIn

    Facebook

    Twitter

    Instagram

    (423) 785-8363

    f

    (423) 321-1682

    Volunteer Building Suite 1200 | 832 Georgia Avenue | Chattanooga, TN 37402

    CONFIDENTIALITY NOTICE
    The information contained in this e-mail message is legally privileged and confidential, and is intended only for the use of the addressee. If you are not the intended recipient, please be aware that any dissemination, distribution or copy of this e-mail is prohibited. If you have received this e-mail in error, please immediately notify us by reply e-mail and delete this message and any attachments. Thank you.




    Original Message:
    Sent: 6/3/2021 4:51:00 PM
    From: Karen Bebow
    Subject: javaScript error

    I want to update a date field on an Opportunity form when an option field changes.  Here is my code:

    function FieldValueChange(){
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(Date.now());
    }

    I'm getting this error when I select an option:

    One of the scripts for this record has caused an error. For more details, download the log file.

    Value should be of type: Date: Parameter Name: valueSession Id: ede42278-0197-4216-8491-7437c7acacf1Correlation Id: ddf74bd3-9372-4b92-96eb-c8495b2849b7Event Name: onchangeFunction Name: FieldValueChangeWeb Resource Name: pwl_weightmodifiedSolution Name: ActivePublisher Name: DefaultPublisherpowellfabTime: Thu Jun 03 2021 16:44:35 GMT-0400 (Eastern Daylight Time) Download Log File

    The option field is called pwl_weighted is the field that triggers the code (OnChange event) and the date field (pwl_wtmodified) is what should be modified.

    Any ideas as to what I am doing wrong?

    Thanks.

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------



     

     

    You are receiving this message because you followed the 'javaScript error' message thread. To unsubscribe from this message thread, go to Unsubscribe.

    Update your email preferences to choose the types of email you receive

    Unsubscribe from all participation emails




    Original Message:
    Sent: 6/4/2021 8:19:00 AM
    From: Karen Bebow
    Subject: RE: javaScript error

    Hi Glen - thank you so much for your reply.  Here is my new code...is this what you mean?

    function FieldValueChange(){
    var date = new Date();
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(date);
    }

    I'm still getting the same error.  I've been known to make simplistic, stupid mistakes - so I won't be surprised if this is one of them!  lol

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------

    Original Message:
    Sent: Jun 04, 2021 08:11 AM
    From: Glen Wolinsky
    Subject: javaScript error

    Try changing you setValue parameter to new Date().  That should return a datetime value with the current timestamp.


    Glen Wolinsky
    IT Application Developer

    LinkedIn
    Facebook
    Twitter
    Instagram
    (423) 785-8363
    f(423) 321-1682
    Volunteer Building Suite 1200 | 832 Georgia Avenue | Chattanooga, TN 37402
    CONFIDENTIALITY NOTICE
    The information contained in this e-mail message is legally privileged and confidential, and is intended only for the use of the addressee. If you are not the intended recipient, please be aware that any dissemination, distribution or copy of this e-mail is prohibited. If you have received this e-mail in error, please immediately notify us by reply e-mail and delete this message and any attachments. Thank you.



    Original Message:
    Sent: 6/3/2021 4:51:00 PM
    From: Karen Bebow
    Subject: javaScript error

    I want to update a date field on an Opportunity form when an option field changes.  Here is my code:

    function FieldValueChange(){
    Xrm.Page.getAttribute("pwl_wtmodified").setValue(Date.now());
    }

    I'm getting this error when I select an option:

    The option field is called pwl_weighted is the field that triggers the code (OnChange event) and the date field (pwl_wtmodified) is what should be modified.

    Any ideas as to what I am doing wrong?

    Thanks.

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------


  • 7.  RE: javaScript error

    GOLD CONTRIBUTOR
    Posted Jun 04, 2021 08:41 AM
    That worked!  Thanks!

    ------------------------------
    Karen Bebow
    Information Systems Manager
    Powell Fabrication & Mfg LLC
    St. Louis MI
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role