Write to CRM footer with JavaScript - javascript

I've noticed that when a mandatory field is not completed and a user attempts to save it adds a message to the form footer
Is it possible to do the same with JavaScript? For example, if I have a custom validation logic that fails (e.g. Start Date must occur within 6 months), is it possible and how would I add a validation message in the same location?

This (MSDN link) is the supported way of displaying custom notifications, similar to the ones that come up for required fields.
The linked MSDN is too long to copy-paste here, essentially we're looking at these functions:
Xrm.Page.getControl(arg).setNotification
Xrm.Page.getControl(arg).addNotification
Xrm.Page.getControl(arg).clearNotification

Business rule can help.
But you may need one more calculated field to achieve your need.

Related

Dynamics CRM - Add/Remove events from a custom made settings page

Hi awesome developers,
Maybe someone can help or put me in the right direction. I want to create a settings page with a few yes/no options.
These settings need to enable or disable form events from different entities. First I was thinking about creating a new entity named foo_Settings with a few fields and yes/no options to trigger on change events. These events will then add or remove events from another entity.
After doing some research, I couldn't find any examples or cases or any info if this could be done through webservices.
I hope someone can help :)
Greets,
Yes, it is a common design pattern in CRM to have a settings/configuration-entity for storing settings such as this.
You can decide to either have one settings-record per organization, or maybe one settings-record per business unit if that suits your needs better. In this way you can have different configurations depending on the need of each business unit.
After creating the settings record and adding some boolean fields, you would write javascript that runs OnLoad of specific entities. This code would fetch the relevant settings-record, read the value of the relevant boolean-field and add a change listener depending on the value of the boolean by calling addOnChange().
After thinking about the settingspage and ways/solutions to create such functionality, there also was something that was itchy..
By creating a settings page and checking in the onload function of each entity with a fetch (odata call), this is not the most fastest or cleanest way. What if thousands of people are using a entity.. This will resulting that thousands of people will fetch.
So my solution will be:
Creating a settingspage (entity).. Onchange event of a setting will fire a odata call to set a record (true or false) on a hidden field in that entity..
In the onload of the entity I will check the value of that hidden field and do logic. This way I will prevent that there will be an Odata call every time the page loads..
Are there any other solutions?

Do I need JavaScript Form validation?

I'm working on some forms for a Website. Currently I have the usual HTML Browser check (with "required"-tag and patterns and stuff in the inputs), I check the values in a JavaScript before submitting and I do a server-sided check of the data after submitting.
Everything works fine, even if I have only one of them enabled, but it seems a little bit overkill to me, so my question is if I can just leave the Javascript check out? Of course I need to keep the server chek :D
Looking forward to your answers!
You must always validate input at serverside. Javascript is optional and it just to make life of your users easier. Your users get better experience. That's it.
All modern browsers support the HTML5 form field attributes. As you are using those, you may skip the JS validation.
To expand a little on the current answers:
Server side validation is always required, you mentioned that.
HTML and Javascript validation are used for different things.
The HTML required tag can be used to check a form's fields are not blank before a form submission.
Javascript validation allows you to be far more flexible with what you want to validate and when. However, it requires more work because it's not as simple as a required tag.
With Javascript you can do far more. Some examples:
Validation that occurs as soon as a user starts to type
Have the box highlight a different colour
Show an error message
Have a big red cross appear next to invalid fields or a big green one next to valid ones
Spin your page around when the user enters something invalid. (don't actually do that)
etc.
Also note browser support for the required tag.

Crm field control order Javascript

I would like to change the order in which the fields in a form get checked.
The field Email should be checked before the field City. They are both obligatory.
I would also like that when the email address is invalid only one Popup is shown (by default I get two- one saying the email is invalid and one saying that the field cannot be null)
Is it possible to change the order of the checks and do the custom checks before the system ones?
Marco
The only supported method of changing the order in which the fields get checked, is changing the order on the form. I'm assuming that CRM just loops through it's collection of controls to perform the field validations. You could attempt to dive into the CRM javascript and figure out a method to hijack it.
A supported way of handling it would be to make the fields not required (either via javascript on the OnLoad, or updating the entity definition itself), and then on the OnSave, writing your own field validation. It's a lot of extra work, and you lose the little red asterisk showing the field is required, but you'd be able to evaluate them in the order you'd like (or display a single message with everything that's missing (why that isn't done by default in CRM I'll never know)), and be able to fix your email invalid / not null message.
CRM does not loop through its collection of controls as specified in the answer above.
The validation of the fields(business required) on a CRM form happen in the order in which they were added to the form, irrespective of where they are placed in the form. So, as of now, the only way to change the order in which they are validated is to add them in the same order as you want them validated.
So far.. I believe the only option to work around this is stated in this link.
http://social.microsoft.com/Forums/en-US/8f402463-23aa-4bc1-862b-4f4093a0cce8/required-fields-order-of-validation?forum=crmdevelopment
Basically you would need to use javascript. Have only one field as mandatory. On change of this field set the next field (in the correct order) to mandatory and so on.. hectic but only way.

Apply onchange to specific form fields and set a new hidden input

I am building an events form, there is an option to add recurring event rules.
I have the form working with related expand to show the recurring event rules. This expand div already has allot of JS to deal with disabling / enabling fields that are not required based on rule types... notably all the recurring form fields are defined in a json object.
I want to be able to detect if the rules have changed during a form save - if the recurring rules have changed I need to do allot of server side processing, so I only want to do this if the rules have changed.
I am thinking about using JS to dynamically apply an onchange call to each field in the recurring form module.
I am pretty new to JS, so before I go further, are there any opinions on how best to do this? Pure Javascript only please!
The final part is to then add a post var to the form, which I can detect in my submit script and then run the required recurring event rules.. This is not a "fix this bit of code" question, more of a best approach question.

How to prepopulate few fields in a form, in a survey

I have a share point survey. When we responding to the survey, as we know, it will open NewForm.aspx. this page contains a ListFormWebpart in which questions from survey list will be displayed.
Now, i need to add few labels before the questions and these label values should be prepopulated from query string. What i am trying to achieve from this is, i wll created a link
with some values in query string and send to specific users. different users might have different values in query string. Whenever they click on the link, it should open the survey with prepopulated label values along with questions in list.
I am not sure, how to do it. I have tried to add some html control to web part(using share point designer) and through JavaScript i have tried to set query string values. Then i tried to put asp controls and trued. it didn't work. I am trying since last 2 days. No progress. I am using SharePoint 2003, WSS2.0
Can anybody, please help me to implement this solution.
You may find it easier to create a webpart with a custom form that enters data into the survey list.
The survey lists are useful as they are quite flexible, but your solution will likely make it hard to change your list in future. That means that a webpart specific for this survey may be a valid design decision for you.
An issue with your current implementation is that passing values specific to different users through the query string does not give you any guarantee that enterprising users will not change those values.
This may not really be an issue depending on your situation, but a custom control will allow you to query the current user and make decisions that way.
I have written some Java Script for reading query string, parsing and assigning values to controls based on their ControlID. I have used Content Editor Web Part to add this JavaScript to the Existing Survey page. Then this script has done job of prepopulating the fields.

Categories