0

I am trying to use a pre-chat form to create a Case, and set a custom checkbox field on the Case object. The name of the field is JJ_Anonymous__c. Here are the important lines in the pre-chat form:

<input type="hidden" id="anon" name="liveagent.prechat:anon" value="1" />
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="AccountId,acctId;Origin,caseOrigin;Subject,caseSubject;RecordTypeId,recType;JJ_Anonymous__c,anon" />
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="RecordTypeId,true;AccountId,true;Origin,true;Subject,true;JJ_Anonymous__c,true" />

The Case is not being created. If I take out the JJ_Anonymous__c from the two relevant lines, the Case is created fine. But somehow adding JJ_Anonymous__c breaks something. I have tried setting the value of the input field for anon to both “1”, as shown above, and “true”. It does not seem to make a difference, it still fails to create the Case in both instances.

Thx, Hamayoun

  • Do you have a namespace prefix registered in this org? – Marty C. Dec 9 '14 at 22:37
  • Hi Marty, no namespace – hamayoun Dec 9 '14 at 22:49
0

@hamayoun, you said that when you take out the reference to your custom field, the form works as expected. So, it appears that the issue is with your reference to the custom field. Can you post a screenshot of the field definition in Salesforce?

Below is a screenshot showing a custom field I have on a Contact object in my org, and the code below shows a working pre-chat form that accepts any entered value for the custom field.

enter image description here

<apex:page showHeader="false">
    <!-- This script takes the endpoint URL parameter passed from the deployment
page and makes it the action for the form -->
    <script type="text/javascript">
    (function() {
        function handlePageLoad() {
            var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
            document.getElementById('prechatForm').setAttribute('action',
                                                                decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
        } if (window.addEventListener) {
            window.addEventListener('load', handlePageLoad, false);
        } else { window.attachEvent('onload', handlePageLoad, false);
               }})();
    </script>
    <h1>Pre-chat Form</h1>
    <form method='post' id='prechatForm'>
        First name: <input type='text' name='liveagent.prechat:FirstNameDetail'
                           id='customField1' /><br />
        Last name: <input type='text' name='liveagent.prechat:LastNameDetail'
                          id='customField2' /><br />
        Favorite joke*: <textarea id="joke" name="liveagent.prechat:JokeDetail"></textarea><br />
        Department: <select name="liveagent.prechat.buttons">
        <!-- Values are LiveChatButton IDs. -->
        <option value="573j0000000L2qg">Chat Now!</option>
        <option value="573a00000000002">Technical Support</option>
        <option value="573a00000000001,573a00000000002">Customer Service if online,
            otherwise Technical Support</option>
        </select><br />
        <!-- Map liveagent.prechat:FirstNameDetail and liveagent.prechat:LastNameDetail
custom detail to Contact's field FirstName and LastName -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map:Contact"
               value="FirstName,FirstNameDetail;LastName,LastNameDetail;sl2__FavoriteJoke__c,JokeDetail" />
        <!-- Specify to query for a matching Contact records FirstName field based on
the value of FirstName -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Contact"
               value="FirstName,true" />
        <!-- Return results only if there is an exact match of FirstName -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Contact"
               value="FirstName,true" />
        <!-- If no match in search, create a new Contact record with the mapped value
of firstname and last name -->
        <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Contact"
               value="FirstName,true;LastName,true;sl2__FavoriteJoke__c,true" />
        <!-- If a new Contact record has been created, open it as a subtab -->
        <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact"
               value="true" />
        <!-- Save the Contact id to transcript's field ContactId -->
        <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Contact"
               value="ContactId" />
        <input type='submit' value='Request Chat' id='prechat_submit'/>
        <style type="text/css">
            p {font-weight: bolder }
        </style>
    </form>
</apex:page>
  • Marty,Have you got this to work with a custom checkbox field, as opposed to a text field? I can get it to work with a text field. – hamayoun Dec 9 '14 at 23:47
  • Good point, @hamayoun. I could not get this to work with a text field. I guess your immediate workaround would be to feed the value into a Text or a Picklist field, and then either render a checkbox in Salesforce as a Formula field, or populate a Checkbox field via a workflow rule. :-( – Marty C. Dec 10 '14 at 3:30
0

It looks like there may be a problem with the Pre-Chat API or the pre-chat form, where checkbox values cannot be passed as expected into Salesforce. As a workaround, you can bind the input element to a Text field, and then either create a workflow rule or use a formula field to convert the text value into a Boolean (a.k.a. checkbox) value.

  • I've logged Case 11324653 with Salesforce Support to see whether this problem is indeed a bug or whether there's an implementation gotcha that we haven't uncovered. – Marty C. Dec 10 '14 at 4:36
0

Another workround would be to use a pre chat controller (which I am already using) and just create the Case there. But it would be good to get it working the "proper" way.

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.