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

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">
<title>Transfer Notes</title>
<script language="javascript" src="" type="text/javascript"></script>
<script type="text/javascript" language="JavaScript">
function initPage()
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.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");
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("Title","test title");
     var updateResult = sforceClient.Update([recObject]);
     sforceClient.debuglog.writeln("record obj:" + recObject.toString());
 } // end for loop
} // end if > 0
} // end function xferNote
<body onload="initPage();">
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.
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.
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.


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?



Well did you get the body and isPrivate fields in your select statement?  Only those fields which you originally queried will be cloned.
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.