pratikshahse
asked on
How to populate a text box on a CRM form using a plug in
I am using the code below to retrieve an e mail address from the contactbase table of the CRM database. I want to populate "pt_email" attribute on the opportunity entity with the e mail that I have retrieved using SQL. Is there a way in a plug in where I can specify to fill a textbox with the value that I have.
if (context.MessageName == "Create")
{
try
{
Key opportunityKey = (Key)entity.Properties["opportunityid"];
opportunityID = opportunityKey.Value;
//get the account id
Lookup accountKey = (Lookup)entity.Properties["accountid"];
accountID = accountKey.Value;
straccountID = accountKey.Value.ToString();
SqlConnection crmconnection = new SqlConnection(CRM_SQL_CONNECTION_STRING);
crmconnection.Open();
manualpurchaseid = MANUAL_PURCHASE_GUID;
SqlCommand command = new SqlCommand("SELECT * from Pt_manual_purchaseExtensionBase where pt_accountid = '" + accountID + "' and pt_manualid = '" + manualpurchaseid + "'", crmconnection);
command.ExecuteNonQuery();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
contactid = reader["pt_contactid"].ToString();
}
reader.Close();
command.Dispose();
SqlCommand contactcommand = new SqlCommand("SELECT emailaddress1 from contactbase where contactid = '" + contactid + "'", crmconnection);
contactcommand.ExecuteNonQuery();
SqlDataReader Emailreader = contactcommand.ExecuteReader();
while (Emailreader.Read())
{
emailaddress = Emailreader["emailaddress1"].ToString();
break;
}
Emailreader.Close();
contactcommand.Dispose();
/// Over here I am trying to put the emailaddress in the "pt_emaiid" attribute of opportunity. it throws an error saying cannot do it. can you tell me what am i doing wrong and what should i do to make it work.
// StringProperty MPemail = (StringProperty)entity.Properties["pt_emailid"];
//MPemail.Value = emailaddress;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.