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
MSchumacherMSchumacher 

Using S-Control to update the ParentID of a Note

I have been trying to use a S-Control to update the ParentId of a Note attached to a custom object.  The update of the Title field is working ok, but when I update the ParentId nothing appears to happen. 
 
I was expecting the Note to now display with a different custom object.  I have included my code.  The sforceClient.Update is successful but the Note remains displayed under the original custom object.  (I have performed a refresh in IE7 to verify the Note did not move).
 
Any ideas?  I believe I am missing something simple at this point.
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Transfer Notes</title>
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js?browser=true" type="text/javascript"></script>
<script type="text/javascript" language="JavaScript">
function initPage()
{
sforceClient.registerInitCallback(queryNote);
sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}",true);
window.setTimeout(";", 1000);
}
function queryNote() {
aResp = confirm("Are you sure you want to transfer the Notes?")
if (aResp == true) {
    sforceClient.getDebugLog();
    sforceClient.debuglog.show();
    sforceClient.debuglog.writeln("serialnum id: {!WEFSN__c.Id}");
    var qryStr = "Select Id,Title,ParentId From Note where ParentId = '{!WEFSN__c.Id}' ";
    sforceClient.debuglog.writeln("qryStr: " + qryStr);
   var queryResult = sforceClient.query(qryStr,xferNote);
    //sforceClient.debuglog.writeln("query size:" + queryResult.size);
    } // end if aResp == true
}   //end function queryNote
function xferNote(queryResult)
{
//var qrySN = "select Id,Name from WEFSN__c where Name = '{!WEFSN__c.Name}' "
var qrySN = "select Id,Name from WEFSN__c where Name = '08111' "
var queryResultSN = sforceClient.query(qrySN);
var recObject = new Sforce.Dynabean("Note");
sforceClient.debuglog.writeln(queryResultSN.toString());
if (queryResult.size > 0) {
 var dynaBean = queryResultSN.records[0];
 var SNId = dynaBean.get("Id") ;
  sforceClient.debuglog.writeln("SNId:" + SNId);
 for (i=0;i<queryResult.records.length;i++) {
     var dynaBean = queryResult.records[i];
     var NoteId = dynaBean.get("Id") ;
     sforceClient.debuglog.writeln("NoteId:" + NoteId);
     recObject.set("Id",NoteId);
     recObject.set("ParentId",SNId);
     recObject.set("Title","test title");
     var updateResult = sforceClient.Update([recObject]);
     sforceClient.debuglog.writeln(updateResult.toString());
     sforceClient.debuglog.writeln("record obj:" + recObject.toString());
 } // end for loop
} // end if > 0
} // end function xferNote
</script>
</head>
<body onload="initPage();">
 
</body>
</html>
jpizzalajpizzala
The parentId on the Note object is probably a "master-detail" relationship (or similar) in the fact that you cannot change it once it has been set.

Instead of reassigning the note record, you may have to duplicate it with the new parentId and delete the original.
MSchumacherMSchumacher
jpizzala,
 
Good idea.  I did change the code to create a new Note with the new ParentId and then delete the old Note.  This seems to work ok.   I have to deal with the body content but the general process looks like it will work.
 
thanks
MSchumacher
 
werewolfwerewolf
Don't create a whole other JS object.  Just take the object you just queried, null out its ID field, and call insert on it.  That will clone it.  Obviously save the old one's ID somewhere for deletion.
MSchumacherMSchumacher

werewolf,

I like this idea.  I changed the code and used the same object, nulled out the Id field and issued the sforeClient.Create.  The new Note object is created but the isPrivate field and Body field did not clone.  Only the Title value was cloned.

Any additional thoughts?

Thanks

MSchumacher

werewolfwerewolf
Well did you get the body and isPrivate fields in your select statement?  Only those fields which you originally queried will be cloned.
MSchumacherMSchumacher
werewolf,
 
Sorry to waste your time.  Your correct, I did not have the isPrivate and Body field in my select during my test.  I just included the two fields and the Note objects were cloned as you indicated.
 
Thanks for the assistance.  It is appreciated.
 
MSchumacher