Home

Tuesday, December 22, 2015

Upsert Request in Dynamics CRM

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Sdk.Messages;

// Upsert request using early binding                           //Upsert request using late binding
Account account = new Account();                              Entity account = new Entity("account");
account.Name = "Early Binding";                                account["name"] = "Late binding";

KeyAttributeCollection acckeys = new KeyAttributeCollection();
acckeys.Add("accountnumber", "012345");              
account.KeyAttributes = acckeys;

UpsertRequest upsertRequest = new UpsertRequest()
{
          Target = account,
};

UpsertResponse response = (UpsertResponse)_orgService.Execute(upsertRequest);

if (response.RecordCreated)
      Console.WriteLine("Record Created in CRM");
else
      Console.WriteLine("Record Updated in CRM");

Tuesday, December 8, 2015

Set Lookup Value using Javascripts in CRM

function set_LookupValue(fieldName, id, name, entityType) {

        if (fieldName != null && id != null) {
            var lookupValue = new Array();
            lookupValue[0] = new Object();
            lookupValue[0].id = id;
            lookupValue[0].name = name;
            lookupValue[0].entityType = entityType;
            Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
        }

    }

Convert subgrid to Comments