Answered by:
Little jScript

Question
-
Hi All
I kindly ask your kind help regarding a simple java script for CRM 2011.
I have on Lead form two fields:
- "telephone1" - this is a text field
- "col_test" - this is a option set
I want to tell CRM the following... If "col_test" value = Client AND "telephone1" value is GREATER or EQUAL 5000, then send alert with text - True.
I use the following code, but it doesn't work.
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute ("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && var myOptionSet.getValue() == „Client“) { alert("True"); } else { alert("False"); } }
Any suggestions?
Thanks in Advance!
All the best,
Andres
Wednesday, February 5, 2014 8:27 PM
Answers
-
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } }
- Proposed as answer by Payman BiukaghazadehEditor Thursday, February 6, 2014 7:24 AM
- Marked as answer by Andres Vallistu Friday, February 7, 2014 2:34 PM
Wednesday, February 5, 2014 8:43 PM -
Hi
function OnOffSwitch()
{
var myOnOffOptionSet = Xrm.Page.getAttribute("field_onoff");
if(myOnOffOptionSet.getText() == "NO")
{togglePolicyInfo();}
}
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } }
Another suggestion, once your post is answered open a new one. Else It might go unnoticed by everyone.
- Marked as answer by Andres Vallistu Monday, February 10, 2014 4:47 PM
Friday, February 7, 2014 2:57 PM -
Another option, if you didn't want to create another function is to just check the value of the new On/Off field in your existing function. Something like this.
function togglePolicyInfo() { var newOptionSet = Xrm.Page.getAttribute(yournewoptionset).getText(); if(newOptionSet == "NO") { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } } }
- Edited by KawasakiRider03 Friday, February 7, 2014 3:07 PM
- Marked as answer by Andres Vallistu Monday, February 10, 2014 4:47 PM
Friday, February 7, 2014 3:07 PM
All replies
-
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } }
- Proposed as answer by Payman BiukaghazadehEditor Thursday, February 6, 2014 7:24 AM
- Marked as answer by Andres Vallistu Friday, February 7, 2014 2:34 PM
Wednesday, February 5, 2014 8:43 PM -
Thank you, it is work now!
These couple of rows was my first java script lines.
Thursday, February 6, 2014 6:42 AM -
Hi
Good to hear that. I hope you enjoy working with CRM and JS too :)
Can you please mark the post which helped you as answered. So that will sort of close the post.
Thanks
Thursday, February 6, 2014 7:49 AM -
Another simple (I suppose) question... Hope somebody could help me.
For instance, I use the same script as above:
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } }
I have made an optionset (or lets name it new on-off switch) with 2 options - "YES" or "NO"
Now I want to tell by jscript that If "YES" is selected, then it should ignore the "function togglePolicyInfo()". But If "NO" selected then the "function togglePolicyInfo()" should be executed. Is it done by some simple way?
Thanks in Advance again!
All the best,
Andres
Friday, February 7, 2014 2:40 PM -
Hi
function OnOffSwitch()
{
var myOnOffOptionSet = Xrm.Page.getAttribute("field_onoff");
if(myOnOffOptionSet.getText() == "NO")
{togglePolicyInfo();}
}
function togglePolicyInfo() { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } }
Another suggestion, once your post is answered open a new one. Else It might go unnoticed by everyone.
- Marked as answer by Andres Vallistu Monday, February 10, 2014 4:47 PM
Friday, February 7, 2014 2:57 PM -
Another option, if you didn't want to create another function is to just check the value of the new On/Off field in your existing function. Something like this.
function togglePolicyInfo() { var newOptionSet = Xrm.Page.getAttribute(yournewoptionset).getText(); if(newOptionSet == "NO") { var myOptionSet = Xrm.Page.getAttribute("col_test"); if (Xrm.Page.getAttribute("telephone1").getValue() >= "5000" && myOptionSet.getText() == "Client") { alert("True"); } else { alert("False"); } } }
- Edited by KawasakiRider03 Friday, February 7, 2014 3:07 PM
- Marked as answer by Andres Vallistu Monday, February 10, 2014 4:47 PM
Friday, February 7, 2014 3:07 PM -
Thank you very much! It's working now.
All the best
Andres
Monday, February 10, 2014 4:47 PM