Tech Support > Microsoft Windows > Windows CRM > Opportunity Retrieve method not returning Id
Opportunity Retrieve method not returning Id
Posted by Mehek on February 25th, 2004


I am trying to add functionality to the CRM such that CRM has the
ability to
duplicate or copy existing opportunities in order to create a new
opportunity.

What I want to do is to create a "Copy Opportunity" button on the
Opportunity form.The button allows to navigate to a custom aspx page.
By enabling parameter passing, I can pass the object type
(opportunity)and object id to the custom aspx page.
The code behind for this custom aspx page should create the new
opportunity using the CRMOpportunity Create method, and maybe just
have a text box where the user could type the name of the Opportunity,
and click on a button 'Save'.

************************************************** *************************
This is where I'm stuck:

The Copy Opportunity button shows up, and the new aspx form shows up
when the button is clicked.

The problem I'm facing now is that I'm trying to retrieve the
Opportunity Id from the Addressable URL, and place it in a textbox to
make sure the Retreive method is working, but its not happening.
The textbox remains empty. Is there any way of debugging the
application by having Console.Writeline statements (I'm using C#) in
the program to know where the program is getting stuck?
I even added a pop up alert in javascript for the Save button on the
aspx page (to Save the new Opportunity name that the user types in the
text box) to see if that works, but even the alert box doesn't show
up.

I am providing my code here:
************************************************** **************************

private void Page_Load(object sender, System.EventArgs e)
{
// Load NameValueCollection object to parse URL Address Line
parameters to get ObjectId and UserId

NameValueCollection coll=Request.QueryString;
// Populate array with ObjectId and UserId.
String[] arr1 = coll.AllKeys;
int loop1, loop2;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
String[] arr2 = coll.GetValues(arr1[loop1]);
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
strOpportunityId = arr2[loop2].Replace("}",null);
strOpportunityId = strOpportunityId.Replace("{",null);
this.txtOpportunityId.Text = strOpportunityId;

}
}

//Instantiate custom ISVOpportunity Class(ISVOpportunity.cs) to
retrieve Opportunity data based on Ojbect ID from MSCRM platform.
ISVOpportunity Opportunity = new ISVOpportunity();

//Return XML string
string strOpportunityRetrieveResult =
Opportunity.RetrieveOpportunity(strOpportunityId);

//Create the XmlNamespaceManager to read XML results from
Opportunity.RetrieveOpportunity method.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("bk", "urn:sample");

//Create the XmlParserContext to read XML results from
Opportunity.RetrieveOpportunity method.
XmlParserContext context = new XmlParserContext(null, nsmgr, null,
XmlSpace.None);

//Create the XMLTextReader to read XML results from
Opportunity.RetrieveOpportunity method.
XmlTextReader reader = new XmlTextReader(strOpportunityRetrieveResult,
XmlNodeType.Element, context);

//Parse the results from Opportunity.RetrieveOpportunity method.
reader.ReadStartElement();
strOpportunityName = reader.ReadString();
this.txtOpportunityName.Text = strOpportunityName;

this.txtOpportunityName.Text = strOpportunityRetrieveResult;
reader.Read();
reader.Close();
}

private void btnUpdate_Click(object sender, System.EventArgs e)
{
Response.Write ("<script language=javascript>alert('In btnUpdate
method');</script>");
ISVOpportunity oOpportunity = new ISVOpportunity();
string strOpportunityCreateNew = oOpportunity.CreateOpportunity("{" +
strOpportunityId+"}");

}
Is there something I'm missing in my code?
Thanks!

Posted by Joe on February 25th, 2004


The parameters that are passed into the custom form are:

Object Type
Request.QueryString("oType")

and
Object ID
Request.QueryString("oId")

Object type is the integer representing the parent form.
Opportunitity in this case.

Object ID is the actual ID of the Opportunity you launched
your custom page from. You should be able to get all the
data you need using this ID. This Id is a character string.

Make sure PassParams="1" is set in the ISV.Config file for
your menu option.

Also I don't see anywhere you are retrieving the User
info. You can't get or set any info in CRM unless it knows
who the user is.