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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Problem with fields with business rules and javascript

(1) ShareShare
ReportReport
Posted on by 448

Hi all

I've 4 custom fields in my crm 
pastedimage1677140813899v1.png

there is a "business rule" that makes data fields mandatory when the bottom left field is set to "yes"; this work well.

With a javascript I would set the data fields at today, below screenshot of event and javascript.

pastedimage1677141400430v2.png

pastedimage1677141507589v3.png

When I set field value on YES, program show this error:

pastedimage1677142809580v5.png
Can someone help me to find where I'm mistaken?

Thans in advance

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to replace Date.now() with new Date() so your assigning should look like:

    Xrm.Page.getAttribute("attribute").setValue(new Date());

  • Suggested answer
    KalpanaNadar Profile Picture
    45 on at

    Hi,

    While calling this function you are calling SetDataToday() and your function name in the script is SetDateToday().

    Try to call the function with the correct name as in the script.

    And to set the date you can try the below piece of code.

    var currentDateTime = new Date();
    Xrm.Page.getAttribute("your_fieldname").setValue(currentDateTime);
    Hope this helps!
  • Suggested answer
    KalpanaNadar Profile Picture
    45 on at

    Hi,

    While calling this function you are calling SetDataToday() and your function name in the script is SetDateToday().

    Try to call the function with the correct name as in the script.

    And to set the date you can try the below piece of code.

    var currentDateTime = new Date();
    Xrm.Page.getAttribute("your_fieldname").setValue(currentDateTime);
    Hope this helps!
  • DiePic Profile Picture
    448 on at

    Hi a33ik and thanks for your reply.

    Not is changed after replacing ....

    pastedimage1677153623886v1.png

    there is some possibility that "businees rule" and "javascript" cannot run togheter?

  • DiePic Profile Picture
    448 on at

    hi KalpanaNadar thanxks for reply.

    The error is the same
    pastedimage1677154102135v1.png

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Ok. Now I see what is happening. Your code is invalid. Check the following lines:

    pastedimage1677154433447v1.png

    you don't have the closing bracket.

    pastedimage1677154461539v2.png

    and here

    pastedimage1677154478841v3.png

    and there

    pastedimage1677154492106v4.png

    and even there

    One more thing:

    pastedimage1677154513727v5.png

    you have try, you don't have catch.

    I would recommend to check your code for syntax errors here - https://jshint.com/

  • KalpanaNadar Profile Picture
    45 on at

    Hi DIE PIC,

    I would request you to check if you are passing the executionContext while calling the SetDateToday function.

    And also try to edit this code in visual studio and verify all the braces are closed properly and function syntax is correct.

    As the error "Web resource method does not exist" we get only when the function is missing braces or any syntax error in the script and the function is not referenced correctly while calling it.

  • DiePic Profile Picture
    448 on at

    Hi a33ik  thanks for link ... very useful tool.

    but after corrections the program not show errors, but dont set the date fields  ...  below the control


    pastedimage1677156483145v2.png

  • DiePic Profile Picture
    448 on at

    Hi KalpanaNadar 

    with https://jshint.com/ I find some error on brackets ... I'm not so good with javascript and its concepts ... what do you mean with "check if you are passing the executionContext while calling the SetDateToday function"?

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Ok. Can you provide types of fields you're getting using getValue?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans