[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 676
  • Last Modified:

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")
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);
manualpurchaseid = MANUAL_PURCHASE_GUID;
SqlCommand command = new SqlCommand("SELECT * from Pt_manual_purchaseExtensionBase where pt_accountid = '" + accountID + "' and pt_manualid = '" + manualpurchaseid + "'", crmconnection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
contactid = reader["pt_contactid"].ToString();
SqlCommand contactcommand = new SqlCommand("SELECT emailaddress1 from contactbase where contactid = '" + contactid + "'", crmconnection);
SqlDataReader Emailreader = contactcommand.ExecuteReader();
while (Emailreader.Read())
emailaddress = Emailreader["emailaddress1"].ToString();
/// 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;

Open in new window

1 Solution
StringProperty name = new StringProperty();
name.Name = "pt_emailid";
name.Value = "xyz@mtccrm.com";

 KeyProperty kp = new KeyProperty();
                kp.Name = "opportunityid";
                kp.Value = new Key(new Guid("opportunityid"));

DynamicEntity stringentity = new DynamicEntity();
stringentity.Name = "opportunity";
stringentity.Properties.AddRange(kp, name)

 TargetUpdateDynamic targetCreate = new TargetUpdateDynamic();
                targetCreate.Entity = "opportunity";

   UpdateRequest create = new UpdateRequest ();

                // Set the properties of the request object.
                create.Target = targetCreate;

                // Execute the request.
                UpdateResponse created = (UpdateResponse )service.Execute(create);


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now