Link to home
Start Free TrialLog in
Avatar of biotec
biotec

asked on

CRM Dynamics javascript to autoload date upon resolve case

I have a field called new_enddate that is not a required field but does need to be populated if someone forgets to put a date in once the case is completed or resolved. How would I do this in javascript. Thanks
Avatar of Biffster007
Biffster007
Flag of New Zealand image

Hi,

You can't achieve this using javascript as you can't tell whether the case is being resolved from any of the available events.  You can achieve what you want either using a plugin or workflow.  You'll find everything you need to know in this article.

https://www.experts-exchange.com/questions/24176730/MS-CRM-4-How-do-i-create-an-On-Change-Event-to-Time-Stamp-a-field.html

Cheers,
MH
You also havea some other options:
(1) use JavaScript to hide the resolve case button until the new_enddate is set.
(2) Use workflow to set the new_enddate (if it is still blank) after the case status is set to resolved.
Avatar of biotec
biotec

ASKER

I'm getting field is read only error but the end_date field is not read only. I also have a quesion about reactivating the case and what happens to the date that was entered?
Avatar of biotec

ASKER

Actually it says the object is read only.
Avatar of biotec

ASKER

Is there a way to throw an alert pop up if the case is trying to be resolved and no End Date is put in?
Hi,

What exactly are you trying to do when you are getting the error that says the field is readonly??

MH
Avatar of biotec

ASKER

It's not generating the error when I'm on the Case. It  shows the error on the workflow in the system jobs. I get  a bunch of waiting statuses for workflow and none of them work. I think it would be easiest to just throw an alert if someone tries to resolve a case without the End Date. Any ideas for that?
When a case is resolved, the entire record is set to read only. It's a major problem with cases that was introduced with CRM 4.0 (3.0 did not have the same "feature").  Some possible workarounds:
(1) In your workflow, you can re-activate the case (change status to active), change the enddate, and the re-resolve the case.  Problem with this is that CRM will then have two "Case Resolution" records (these are activity types).  If you're not using case resolutions to bill your hours, or for other reporting purposes, then this isn't a problem.  If you are, then using this first appraoch, you'll need to delete the first resolution -- I don't have a clever way that you can do that off the top of my head.
(2) I think there is probably a way that you can get your desired outcome using a workflow - but it's tricky.  You can probably hook into the resolve case button click event and set the enddate to required.  Most likely this is not "supported" - but I believe it can be done.
(3) You could probably (I'm not sure on this one) write a .NET plugin that fires when the resolve case event is fired, but before the status is set to resolved.
(4) Here's an idea that may be the most workable:
* Create a custom field called "Resolve Case" - make it a bit field
* When the user checks the box, use javascript to change the enddate to required.  
* Setup a workflow that fires when the case is saved - check to see of "resolve case" is checked - if it is, then use the workflow to resolve the case automatically
* If you can get the above to work, you can then hide the Resolve Case button on the case form (tricky, but it can be done with JavaScript I think).
Avatar of biotec

ASKER

Thanks but that is quite a bit of work. I think it would be much simpler to just be able to set up an alert that if they click on resolve and the End Date is blank an alert pops up or something like that. Is that doable?
Avatar of biotec

ASKER

I actually need quite a few pop up alerts such as if a field needs to be whole number only how would you pop up an alert to say that you've entered a decimal or just to say whole numbers only etc.
Unfortunately, what you are trying to do is simply not an easy thing to do in Microsoft CRM.  In essence, you would like to trigger an event when a user clicks a button (i.e. Resolve Case) BEFORE CRM does what it would normally do (i.e. open the Resolve Case dialog box).  There may be some tricky way to do this using JavaScript, but I am not sure of how to do it and I am certain that it would not be supported.
Attach this JavaScript to the OnChange event of your EndDate field:
if (crmForm.all.new_enddate.DataValue != null)
      resolve();
What that will do is to open the case resolution form automatically when the enddate field is filled in by the user.  If that works, then you can use some separate JavaScript to hide the Resolve Case button from the user, so the only way the user can resolve the case is to enter an enddate - at which point the case will automatically be resolved.
There are a number of other variations on this concept that you can use, depending on what specific user experience you are after - the above was the simplest solution I could think of.
----
For your second question, alerts, you can use JavaScript like this (in the OnChange event behind the field in question):
if (crmForm.all.{your field name}.DataValue >= 100)
     alert("You can only enter values of less than 100 into this field");
You'll need to change the if statement to reflect the value that you're testing for.
Avatar of biotec

ASKER

Thanks. How would I just hide the Resolve Case button if the End Date was not filled in? Also what I wanted to do was to do an alert if a filedtype was not a whole number, is there anyway to do that?  
ASKER CERTIFIED SOLUTION
Avatar of crm_info
crm_info
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial