You need to sign in to do that
Don't have an account?
MsKnight
Apex Button - Enhanced List View Error
Before the Summer '08 release we created a custom list button that executes Javascript and calls an Apex class. It was working perfectly until we turned on the enhanced list view. Below is the code and the error:
I have narrowed it down to the point where it tries to retrieve the Name and Purchase_Order__c from the records. I haven't been able to find any documentation on this function changing.
Any thoughts?
Thanks!
Message Edited by MsKnight on 06-16-2008 03:57 PM
Code:
{!REQUIRESCRIPT("/soap/ajax/11.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/11.0/apex.js")} var errnum = 0; var errmsg = ""; var idArray = {!GETRECORDIDS($ObjectType.SFDC_Purchase_Requisition__c)}; if (idArray[0] != null) { var records = sforce.connection.retrieve("Name,Purchase_Order__c", "SFDC_Purchase_Requisition__c", [idArray]); if (records.length > 0) { for (var i = 0; i < records.length; i++) { if (records[i].SFDC_Purchase_Order__c != null) { errnum++; errmsg += records[i].Name + "\n"; } } if (errnum == 0) { var result = sforce.apex.execute("POButton", "createPO", { reqsId: idArray }); alert("PO Created!"); window.parent.location.href = "/" + result[0]; } else { alert("A PO already exists for: \n" + errmsg); } } } else { alert("Please select at least one record."); }
Code:
{faultcode:'sf:MALFORMED_ID', faultstring:'MALFORMED_ID: bad id function (B){ var A = this.indexOf(B); if(A != -1) { this.splice(A,1); } return this; }
Thanks!
Message Edited by MsKnight on 06-16-2008 03:57 PM
some javascript libraries override or extend the array object
ajax.js does not know this has occured and skips a check for function when seralizing the array
the following does check
you must add this after you include ajax.js
note the check for typeof() == function
this avoids seralizing a function that is attached to the idArray
so the complete code should look something like this
Message Edited by Ron Hess on 06-16-2008 08:39 PM
I added the code you suggested to the button and I still receive this error:
Any thoughts?
Thanks!
again, this must be after the library is included, and before it is used.
After much digging around, we figured out that it was simply an issue with how it was seeing the array. To fix it, we changed the code from:
to:
That seemed to clear it up.
Thanks for all of your help!
- J Knight