0

Here is my code in the button:

if({!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Closed"))}){
     alert("Close Work Order button has not been completed, the Work Order Order Status has not been set to Closed or Unresolved");
}
else{
    window.top.location.href =
     '/apex/loop__looplus?sessionId={!$Api.Session_ID}&eid={!SVMXC__Service_Order__c.Id}&filter={!SVMXC__Service_Order__c.Email_Integrator__c}Service&servcont_Name={!SVMXC__Service_Order__c.SVMXC__Contact__c}&servcont_email={!SVMXC__Service_Order__c.Contact_Email__c}Service&servcont2_Name=
{!SVMXC__Service_Order__c.Integrator__c}&servcont2_email=
{!SVMXC__Service_Order__c.Integrator_Email_Contact__c}';

}

This actually works if I remove the following, which I don't understand why, as ALL these fields do exist in my Service Order obect and works on it's own without the IF statement.

Service&servcont2_Name=
{!SVMXC__Service_Order__c.Integrator__c}&servcont2_email=
{!SVMXC__Service_Order__c.Integrator_Email_Contact__c}

After I can resolve this issue, I also need to add an addition condition for 'OR (||)' , which also isn't working. Adding the additional condition actually throws the Alert to pop-up no matter what the value of the SVMXC__Service_Order__c.SVMXC__Order_Status__c field is, including "Closed" and Unresolved"

if({!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Closed"))} 
                      || {!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Unresolved"))}){
     alert("Close Work Order button has not been completed, the Work Order Order Status has not been set to Closed or Unresolved");

}
1

In JavaScript, a string must not span more than one line. In other words:

// valid
var helloWorld = 'Hello World';
// invalid
var helloWorld = 'Hello
 World';

However, you can make it valid by escaping the newline:

// valid
var helloWorld = 'Hello\
 World';

So, you must escape the end of each line so the string continues on the next line, keep the entire text on one continuous line, or use + to concatenate the various parts of the string together, making sure each string is entirely self-contained on a single line.

For your OR issue, you've miscalculated your Boolean logic. You meant to use AND instead, because you want it to work only when it is not either value. Logically, if one condition is true, the other will be not true, and OR will cause the logic to trigger anyways. Your formula would look more like this:

{!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Closed")) && NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Unresolved"))}

Personally, I'd probably rewrite this using De Morgan's Laws so that it makes more sense logically:

{!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Closed") || ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Unresolved"))}

Notice how it is possible to evaluate the condition entirely in the formula; there's no need to evaluate each separately.

  • Thank you, I do see what you mean with the escape... I think I have that part figured out. My issue still remains with the !NOT statement .... do I still need the IF, no matter what I do it's failing.... and yes I can see how the condition can be reused, that's good to know! – Sonia Feb 10 '17 at 21:49
  • @Sonia Yes, you still need the if(...) part, I was focused just on the actual expression(s). – sfdcfox Feb 10 '17 at 21:55
  • Ok, I'll give it another go.... – Sonia Feb 10 '17 at 22:01
  • When I run this through JSLint, I get this: Expected an identifier and instead saw '!'. if({!NOT(ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Closed")) || ISPICKVAL(SVMXC__Service_Order__c.SVMXC__Order_Status__c, "Unresolved")}){ – Sonia Feb 10 '17 at 22:05
  • @Sonia Yes, JSLint is going to complain about merge fields; it does not understand how they work. In Salesforce, the merge field will not been seen by JavaScript; only a "true" or "false" value will be put in its place. – sfdcfox Feb 10 '17 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.