web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

silverlight to retrieve Account Id in CRM 2011

(0) ShareShare
ReportReport
Posted on by 60

I am using silverlight to create a button that would update a field in CRM 2011

How would I retrieve accountid from [AccountBase] table and then update field in the [AccountBase] table.,

when the user clicks on the account record, is there away to get it's current accountid?

my current code works but I am hard-coding the account id, how do I retrieve the current account id? thank you

    private void btnUpdateAccount_Click(object sender, RoutedEventArgs e)
    {
        Guid _accountid = new Guid("64693B0D-463B-E211-ABBA-000C290C2C64");
        Account _account = new Account();
        _account.AccountNumber = "121276541";
        _account.AccountId = _accountid;
        _context.AttachTo("AccountSet", _account);
        _context.UpdateObject(_account);
        _context.BeginSaveChanges(UpdateAccount, _account);
    }
    private void UpdateAccount(IAsyncResult result)
    {
        _context.EndSaveChanges(result);
        Account _account = result.AsyncState as Account;
        textBoxUpdate.Text = "update end.";

    }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    Re: silverlight to retrieve Account Id in CRM 2011

    If you are using the Silverlight control within your form, you can use the following code within your Silverlight Application:

    string accountId = App.Current.Host.InitParams["id"];

    Make sure that on the form design, in the properties of the Silverlight control -> Formatting Tab check the "Pass record object-type and unique identifer as parameters".

    You can also use the the dynamic object:

    dynamic Xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");

    var contactid =  Xrm.Page.data.entity.getId();

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans