locked
How to use attribute value from contact to an account RRS feed

  • Question

  • Hello,
    I'm using Microsoft Dynamics CRM 4.0

    I am new to scripting in CRM and I'm hoping someone could help me with this problem I have.
    I have and int attribute with a number in contacts. I want the parrent account to use this nr, and input it into another int attribute.

    Does anyone know how to do this? I would be very happy for all help!
    Tuesday, December 2, 2008 9:31 AM

Answers

  • Hi,

    You might want to refer to these code snippets

    hope this helps,

    hadi teo.

    ==

               // The purpose of this code snippet
                // is to retrieve the emailaddress of the specified contact
                // and update the parent customer of the current contact - email address


                // retrieve the contact object with specified contactid
                contact c = new contact();

                TargetRetrieveContact target = new TargetRetrieveContact();
                target.EntityId = new Guid("902DC925-3EC0-DD11-BD1C-0003FFBAD763");
                RetrieveRequest req = new RetrieveRequest();
                req.Target = target;
                req.ReturnDynamicEntities = false;

                req.ColumnSet = new AllColumns();
                RetrieveResponse res = (RetrieveResponse)service.Execute(req);

                c = (contact) res.BusinessEntity;


                // update the parent customer of the specified contact
                // and update the email address attribute with the contact email address
                account acc = new account();
                acc.accountid = new Key();
                acc.accountid.Value = c.parentcustomerid.Value;
                acc.emailaddress1 = c.emailaddress1;


                TargetUpdateAccount target2 = new TargetUpdateAccount();
                target2.Account = acc;
                UpdateRequest req2 = new UpdateRequest();
                req2.Target = target2;
                UpdateResponse res2 = (UpdateResponse)service.Execute(req2);

    Tuesday, December 2, 2008 2:01 PM

All replies

  • Hi,

    Can you please make this more clear?

    "I want the parrent account to use this nr, and input it into another int attribute"

     

    Tuesday, December 2, 2008 10:34 AM
  • I’m sorry for the bad explanation. Ill try to make it more clear.

    First I have made an int attribute under Contact with the name "new_newswatchertotal". In this box I want the sales department to enter in the nr of subscribers.

     

    Then I made another int attribute, "new_newswatchertotal", under Accounts that I want to automatically the nr from the Contact and then adds it in Account under the attribute "new_newswatchertotal". (It there is a problem with those attributes being the same name, I can change them.)

    Anyway; I want the attribute under account to count the nr from contact and get the total from all the contacts that has the account as Parent Customer.

     

    I hope this was clearer: basically it is like this:

    I want all the numbers from the attribute under contact to add up in a total to there Parent Customer, so that I can see the total nr of subscribers per account.

     

    Was this clearer? Thank you for your time!

    Tuesday, December 2, 2008 11:26 AM
  • Use a workflow--do a workflow that fires on create/update of that number field of the contact and insert one step to update the related account record.  From there with the form assistant you can set that int attribute on the parent account to the value of the contact int field.

     

    Tuesday, December 2, 2008 12:09 PM
    Moderator
  • Hi,

    You might want to refer to these code snippets

    hope this helps,

    hadi teo.

    ==

               // The purpose of this code snippet
                // is to retrieve the emailaddress of the specified contact
                // and update the parent customer of the current contact - email address


                // retrieve the contact object with specified contactid
                contact c = new contact();

                TargetRetrieveContact target = new TargetRetrieveContact();
                target.EntityId = new Guid("902DC925-3EC0-DD11-BD1C-0003FFBAD763");
                RetrieveRequest req = new RetrieveRequest();
                req.Target = target;
                req.ReturnDynamicEntities = false;

                req.ColumnSet = new AllColumns();
                RetrieveResponse res = (RetrieveResponse)service.Execute(req);

                c = (contact) res.BusinessEntity;


                // update the parent customer of the specified contact
                // and update the email address attribute with the contact email address
                account acc = new account();
                acc.accountid = new Key();
                acc.accountid.Value = c.parentcustomerid.Value;
                acc.emailaddress1 = c.emailaddress1;


                TargetUpdateAccount target2 = new TargetUpdateAccount();
                target2.Account = acc;
                UpdateRequest req2 = new UpdateRequest();
                req2.Target = target2;
                UpdateResponse res2 = (UpdateResponse)service.Execute(req2);

    Tuesday, December 2, 2008 2:01 PM
  • Thanks alot!
    I will try this! Big Smile
    Wednesday, December 10, 2008 9:52 AM