I try to create a case as soon as I accept the chat. The case record type should be picked from the guest user profile which I mentioned only one, but in console the case gets created with the default type. I have mentioned the case record type tag as well, but still it is not working.
Method One : PreChat API Only (Record Type by ID)
Create a hidden input field that will host the Record Type by Id, because RecordType Name is not supported in live agent:
<input type="hidden" name="liveagent.prechat.caseRecordType" value="RECORDTYPEID" />
Then in your findorcreate.map, make sure you are mapping caseRecordType to RecordTypeId in Salesforce, like this (you will likely have other items in your map too, but I removed mine for simplicity in this answer and only left RecordType:
<input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="RecordTypeId,caseRecordType" />
Then, lastly, in your findorcreate.map:DoCreate, make sure you include RecordTypeId,true:
<input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="RecordTypeId,true;Origin,true;Subject,true;Status,true;" />
As noted by another answerer, the downside to this implementation is that you will need to change the hard coded RecordTypeId in the preChat VF page when deploying it to a production org, since the RecordTypeId will be different.
Method Two : PreChat API and Workflow Rule (Record Type by Name)
Using the PreChat API, we have the ability to set any field on the case object, similarly to the way that we are setting record type in Method One. StackExchange user PepeFloyd suggests that if you are setting any of your values to a unique value that is only used during a live agent chat, then you can also add a workflow rule that fires off of meeting that criteria that sets the record type for you.
First we set our unique value on the case object. In this example, we set the case origin to "Chat" and assume that "Chat" is never used as the origin in any other scenario. We then add it to the map, and the doCreate:
<input type="hidden" name="liveagent.prechat.caseOrigin" value="Chat" /> <input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin" /> <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;" />
Then our Workflow Rule would look something like this:
And our Field Update:
You would of course set it to your appropriate Record Type.
I doubt there is some internal mechanism to query recordtypeId here ,one of the following ways to address this problem is use hardcoded recordtype Id as below
<input type="hidden" name="liveagent.prechat:caseRecordType" value="573a00000000001" /> <input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin;Subject,caseSubject;RecordtypeId,caseRecordType;" />
Only drawback i see is in production you may need to change the recordtypeId copied using developer console or set up menu
I have also found that if part of your case creation has a need to link to an existing contact, and you want to find the contact by email address and with a specific record type (like 'Customer') then we have a similar problem. You need to hard code a record id for the contact.
Because 'liveagent.prechat.findorcreate.map.doFind:Contact' can't be filtered with a record type name. But it can with a RecordTypeId