Answered by:
How to check if an opportunity is open or closed?

Question
-
Hello,
I have created a nifty jScript for my opportunity onLoad form event. However, I only want this script to be launched if the Opportunity is OPEN (never-mind the status reason, just if it is OPEN OR CLOSED).
What sort of IF conditional should I use to check if the opportunity is closed or open, in order to execute my script as desired?
I am using Dynamics CRM 2011
Thanks for the help!
P.
- Edited by pmdci Tuesday, April 19, 2011 2:46 PM
Tuesday, April 19, 2011 2:25 PM
Answers
-
Unfortunately Faisal provided a CRM 4.0 example, but if you run it through the jscript convertor tool and you should be good to go.
http://crm2011scriptconvert.codeplex.com/
Good luck!
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Proposed as answer by Jamie MileyModerator Tuesday, April 19, 2011 2:49 PM
- Marked as answer by pmdci Tuesday, April 19, 2011 4:23 PM
Tuesday, April 19, 2011 2:49 PMModerator
All replies
-
Javascript only works when the form is open, any field is change or on save. Javascript doesnot work on closed form. Therefore if you put some code on load than it will always workflow when some one opens the form.
Regards FaisalTuesday, April 19, 2011 2:32 PM -
Faisal,
Sorry but this is not the case. Perhaps I wasn't being clear
My script IS being triggered when opening a form for an opportunity that is closed. This is because my script is set for the onLoad event of the form. What happens is that my script is doing some calculations that it shouldn't since the opportunity is closed. Well, the user wouldn't be used to save those changes (since the opportunity is closed), but the problem is that when viewing a closed opportunity, the script is doing some calculations that it shouldn't.
Going back to my original question:
I have a jScript that is triggered on the onLoad event of the opportunity form. What I want is to set a conditional so the script only does what it should when the opportunity is open. How can I do that?
Regards,
P.
Tuesday, April 19, 2011 2:38 PM -
this will look different depnding on whether yo uare using 4.0 or 2011. Which version are you running?
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Tuesday, April 19, 2011 2:44 PMModerator -
Sorry! 2011 all the way! :)
- Proposed as answer by Jamie MileyModerator Tuesday, April 19, 2011 2:49 PM
- Unproposed as answer by Jamie MileyModerator Tuesday, April 19, 2011 2:49 PM
Tuesday, April 19, 2011 2:45 PM -
You can check the statecode 0 for open opportunities. Statecode field should be on the form.
if (crmForm.all.statecode.DataValue == 0) {
//Put your logic here.
}
Regards Faisal
- Proposed as answer by Jamie MileyModerator Tuesday, April 19, 2011 2:49 PM
Tuesday, April 19, 2011 2:46 PM -
Unfortunately Faisal provided a CRM 4.0 example, but if you run it through the jscript convertor tool and you should be good to go.
http://crm2011scriptconvert.codeplex.com/
Good luck!
Jamie Miley
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Proposed as answer by Jamie MileyModerator Tuesday, April 19, 2011 2:49 PM
- Marked as answer by pmdci Tuesday, April 19, 2011 4:23 PM
Tuesday, April 19, 2011 2:49 PMModerator -
Jamie and Faisal, It worked like a charm. Great hint on the jScript CRM4 to CRM 2011 converter, by the way!
Here is how it looks like on Dynamics CRM 2011:
SalesPipelineCalc = function() { // Only perform the function if Opportunity is open if (Xrm.Page.getAttribute("statecode").getValue() == 0) { // Script goes in here... }
Thanks!
P.
Tuesday, April 19, 2011 4:24 PM