You need to sign in to do that
Don't have an account?
Querying data from one object to update on another
Hi, I'm new to Salesforce development and don't know enough about Javascript.
I have taken an example of Javascript to update a Case Record and it works with a text value. I would like to update the case with a value queried from another object (there is no relationships between the two objects so it can't be done via a workflow).
I am pretty sure the error in my code is something to do with Javascript Arrays because I can verify that the Query on my lookup Object is returning a value.
Could someone please help me out and point me in the right direction with how to get the value out of the query to use in the update of the Case.
Thanks
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} var updateRecord = new Array(); var myquery = "SELECT Id FROM Case WHERE Id = '{!Case.Id}' limit 1"; result = sforce.connection.query(myquery); records = result.getArray("records"); var lkupquery = "Select LookupValue__c from CustomObject__c where OwnerId = '{!$User.Id}' and Value__c < 10 limit 1"; var lkupresult = sforce.connection.query(lkupquery); var lkuprecords = lkupresult.getArray("lkuprecords"); if (lkuprecords.length == 1) { var LkupVal = lkuprecords[0]; } else { alert("Something went wrong here"); } if(records[0]) { var update_Case = records[0]; update_Case.MyTextField__c = LkupVal; updateRecord.push(update_Case); } result = sforce.connection.update(updateRecord); parent.location.href = parent.location.href;
My problem starts with the line "var lkuprecords = lkupresult.getArray("lkuprecords");"
I am trying to update the case field MyTextField__c with the LookupValue__c from the CustomObject__c
Hey ,
I just twik the variable declaration,
Thanks,
bForce
All Answers
Hey ,
I just twik the variable declaration,
Thanks,
bForce
Thanks, I'm not sure if it was the variable naming, or something else, but I finally worked through it and got it working.
Here is what I did.
I'm sure it is terrible code, but it does the job.