0

I have a Salesforce Docusign Custom Button in a custom object that I would like to add a simple validation. This will prevent the user from starting a new Docusign envelope if the validation is met. Using OnClick JavaScript this is what I have so far but I am getting an error message indicating

"Invalid ID field: undefined".

If I add the validation after the {!REQUIRESCRIPT("/apex/DocuSign_JavaScript")} then the button does nothing when clicked.

var payment = "Paid In Full";

var paymentstatus = '{!EFI_Event_Expenses__c.Payment_Status__c}';

if (paymentstatus=payment) { 
    alert = ("Unable to process payment {!EFI_Event_Expenses__c.Payment_Status__c}");
} 
else 
    {!REQUIRESCRIPT("/apex/DocuSign_JavaScript")} 

DST = '{!EFI_Event_Expenses__c.DocusignTemplate__c}'; 

CES = 'Team Florida - Request for Payment'; 

CEM = 'Request for payment of expense for {!EFI_Event_Expenses__c.Campaign__c}'; 


window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!EFI_Event_Expenses__c.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
1
  • You do seem to have a logic issue on your if statement: *if (paymentstatus=payment) { * Should likely be == instead. – dphil Feb 1 '16 at 17:46
1

There's a few things odd with the code you've posted here. Let's run through it:

You're creating 2 variables: payment and paymentstatus. Both of these would technically be Strings. I'm guessing in your if statement you're trying to compare the two values, but using a single = you're trying to set paymentstatus to payment.

The first part should look like this, alls it will do is create a browser alert that will say:

Unable to process payment Paid in full

if (paymentstatus == payment) { 
  alert = ("Unable to process payment {!EFI_Event_Expenses__c.Payment_Status__c}");
}

Now your else statement is calling the file at {!REQUIRESCRIPT("/apex/DocuSign_JavaScript")}. But that will only get called if the paymentstatus is not equal to payment. If paymentstatus is equal to payment. The code below your if else is still going to run and I'm guessing your variables DST, CES and CEM depend on that script being called? You don't appear to be creating them anywhere in the code you've provided.

The error could be a result of that.

Presumably you don't want anything to happen if the payment can't be processed? In which case you'd just want a little bit of formatting to your code by adding a few brackets. Something like below:

var payment = "Paid In Full";

var paymentstatus = '{!EFI_Event_Expenses__c.Payment_Status__c}';

if (paymentstatus == payment) { 
  alert = ("Unable to process payment {!EFI_Event_Expenses__c.Payment_Status__c}");
} 
else {
  {!REQUIRESCRIPT("/apex/DocuSign_JavaScript")} 

  DST = '{!EFI_Event_Expenses__c.DocusignTemplate__c}'; 

  CES = 'Team Florida - Request for Payment'; 

  CEM = 'Request for payment of expense for {!EFI_Event_Expenses__c.Campaign__c}'; 


  window.location.href ="/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&SourceID={!EFI_Event_Expenses__c.Id}&RC="+RC+"&RSL="+RSL+"&RSRO="+RSRO+"&RROS="+RROS+"&CCRM="+CCRM+"&CCTM="+CCTM+"&CRCL="+CRCL+"&CRL="+CRL+"&OCO="+OCO+"&DST="+DST+"&CCNM="+CCNM+"&LA="+LA+"&CEM="+CEM+"&CES="+CES+"&SRS="+SRS+"&STB="+STB+"&SSB="+SSB+"&SES="+SES+"&SEM="+SEM+"&SRS="+SRS+"&SCS="+SCS+"&RES="+RES;
}

In other words, if paymentstatus is not equal to payment, execute the code within that else block. Otherwise you'd only be outputting that alert. Nothing else would happen.

I'd say this would be a good start, but it might not completely fix your problem!

4
  • Thank you for your reply! The extra = fix the issue with the validation and it did create the docusign envelope if not = "Paid In Full" Unfortunately now if if does = "Paid In Full" when click it does nothing. The alert does not come up at all. I am declaring the DST, CES and CEM variable I had removed it. Here is the complete code as of now. – Mildred Morales Feb 1 '16 at 18:56
  • @MildredMorales good to know! Check the capitalisation and spelling of the {!EFI_Event_Expenses__c.Payment_Status__c} field. Make sure they totally match up. Also thinking about it in JS you don't need to do alert = ("Abc123"), it should just be alert("Abc"). You can use the Developer Console in most browsers (normally F12) to debug JavaScript. :) – Dan Jones Feb 2 '16 at 8:02
  • 1
    It works!!! Basically all of the issues were indeed java related. Thank you so much. – Mildred Morales Feb 4 '16 at 18:04
  • Hey Poet! Hope all is well. Wondering if you can help me out on a second if statement for this same code. If Grant Program equals "A" then use this Docusign Javascript else if Grant Program equal "B" then use this a different Docusign Javascript else error Grant Program not setup for payment. – Mildred Morales May 20 '16 at 21:05

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.