function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vandervander 

create case with ajax

hello -

i'm trying to create a case w/ the ajax toolkit and having some issues. Here is the javascript function:

//create case from asset using contact id and record type info
function createCase() {
//check that all required variables are set
if (assetId != "" && conId != "" && proTypeId != "" && proType != "") {
//create case dynabean
var _case = new DynaBean("Case");
_case.set("AssetId", assetId);
_case.set("ContactId", conId);
_case.set("RecordTypeId", proTypeId);
_case.set("Type", proType);
//create 1 new case
var saveResult = sforceClient.Create(_case);

alert("Here is the save result:"+saveResult.toString());

}
else {
alert("Error: Information required to create a Case directly from this Asset is missing.");
//return to asset page
frameNav(assetUrl);
}
}

saveResult.toString() is being returned as a null so i'm not getting any feedback. the variables being set are correct. any ideas/suggestions are much appreciated! thanks!
DevAngelDevAngel

Hi vander,

Try this line:

var saveResult = sforceClient.Create([_case]);

There is a bug in the toolkit.  The documentation states that you can pass a single object or an array to the create call, but it is only working for an array.

Placing _case inside square brackets makes it an array.

vandervander
thanks so much. that fixed it. now - from the resulting alert, it looks like the ID of the newly created case is being passed back. is that true? if so how can i access that ID?

thanks again - i really appreciate the help!
DevAngelDevAngel

What is returned is either a SaveResult array or a SoapFault.  You access the values returned by using "get" syntax.

So in your code you would do:

	for (var i=0;i<saveResult.length;i++) {
		var oneSaveResult = saveResult[i];
		if (oneSaveResult.success == true) {
			alert("The new id is: " + oneSaveResult.get("Id"));
		} else {
			alert("The did not succeed: " + oneSaveResult.errors[0].message);
		}
	}

Message Edited by DevAngel on 08-17-2005 11:56 AM

vandervander
Actually, the line using '.get("Id")' returns an error:

alert("The new id is: " + oneSaveResult.get("Id"));

Calling '.id' directly works properly. Like this:

alert("The new id is: " + oneSaveResult.id);

Thanks for pointing me in the right direction though!

Message Edited by vander on 08-17-2005 01:12 PM

DevAngelDevAngel

(Sheepish grin)  Guess I actually ought to test the code first.  To be clear and rectify the implied method of access properties - the "get" and "set" are used only for DynaBeans (a DynaBean is the class that is used to create an SObject), for all other objects you would use the dotted syntax.  There are other alternatives due to the way javascript objects work, but for simplicity sake, the dotted is best.