You need to sign in to do that
Don't have an account?
vander
AJAX - update AssetId on Case problem
Hi -
I'm working on an S-Control using the AJAX toolkit to update the AssetId on a Case. My query is returning the correct Case Id and I have the correct AssetId to update with but my update is not working. My javascript function is below. This is my first time working with the AJAX toolkit and Case object so my syntax is probably incorrect. Any suggestions are appreciated:
function IsChecked(form, element_name, value)
{
//query sforce for current Case and current AssetId
var queryResult2 = sforceClient.Query("Select Id, CaseNumber, AssetId from Case Where CaseNumber = '" + caseId + "'");
//new array to hold results of updates
var updateObjects = new Array();
for (i = 0; i < form.elements.length; i++) {
if ((form.elements[i].name == element_name) && (form.elements[i].checked)) {
var aid = form.elements[i].value;
var _case = queryResult2.records[0];
//set case AssetId to checked value
_case.set("AssetId", aid);
//push updated AssetId to update array
updateObjects.push(_case);
}
}
if (updateObjects.length > 0) {
var x = window.confirm("Are you sure you want to update "+ updateObjects.length +" record(s) ?");
if (x) {
var sr = sforceClient.Update(updateObjects);
//window.parent.parent.location.href = retUrl;
window.close();
}
} else {
alert("No Records will be updated");
//window.parent.parent.location.href = retUrl;
window.close();
}
}
I'm working on an S-Control using the AJAX toolkit to update the AssetId on a Case. My query is returning the correct Case Id and I have the correct AssetId to update with but my update is not working. My javascript function is below. This is my first time working with the AJAX toolkit and Case object so my syntax is probably incorrect. Any suggestions are appreciated:
function IsChecked(form, element_name, value)
{
//query sforce for current Case and current AssetId
var queryResult2 = sforceClient.Query("Select Id, CaseNumber, AssetId from Case Where CaseNumber = '" + caseId + "'");
//new array to hold results of updates
var updateObjects = new Array();
for (i = 0; i < form.elements.length; i++) {
if ((form.elements[i].name == element_name) && (form.elements[i].checked)) {
var aid = form.elements[i].value;
var _case = queryResult2.records[0];
//set case AssetId to checked value
_case.set("AssetId", aid);
//push updated AssetId to update array
updateObjects.push(_case);
}
}
if (updateObjects.length > 0) {
var x = window.confirm("Are you sure you want to update "+ updateObjects.length +" record(s) ?");
if (x) {
var sr = sforceClient.Update(updateObjects);
//window.parent.parent.location.href = retUrl;
window.close();
}
} else {
alert("No Records will be updated");
//window.parent.parent.location.href = retUrl;
window.close();
}
}
Hi vander,
Let's try this:
Message Edited by DevAngel on 08-10-2005 09:18 AM
your code to show return errors helped me figure it out.
the update was erroring out because i was selecting CaseNumber in my query.
because this was in my update object, it was trying to update the CaseNumber which obviously is not allowed.
once i removed that from the select statement everything worked great!
Yup, it's a little extra code, but the time spent to write the extra code is a lot less than staring till your cross eyed at your lines of code.