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

How to get id from Create response

I am sort of posting this question twice - my apologies.  I have done a bit more research and think I am on the right track but have hit a wall.  

I am trying to obtain the key of a new opportunity created by my sforce control..  The code I am using was initially posted by DevAngel and demonstrated how to calculate a field and perform an update using javascript and msxml.  I have modified the code to do clone operation from an existing opp.

The problem is that I can't seem to get to the id that is returned in the response from the create call per the API.  I can see the key when I display the msxml.responseText.   For some reason the selectNodes isn't working because objNodeList is undefined. 

Here is the code I am using to attempt to retrieve the "id" node that is returned per the API doc.  Any guidance would be greatly appreciated. 

if (status == 200)
  xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
  xmlDoc.setProperty("SelectionNamespaces", "xmlns:sf=''");
  var objNodeList = xmlDoc.documentElement.selectNodes("//sf:id");
  var newoppid = objNodeList.item(0).text;
  document.write("<br><strong><center>Opportunity successfully cloned.");
  //window.parent.parent.location.href="" +  newoppid;

the id element isn't in the urn:sojbect... namesapce. you need to change this
xmlDoc.setProperty("SelectionNamespaces", "xmlns:sf=''");
xmlDoc.setProperty("SelectionNamespaces", "xmlns:sf=''");
That did it. Thanks!