Qualify Lead in MS CRM 2011 - dynamics-crm-2011

I'm newbie to CRM. I want to qualify a lead to create opportunity. I'm passing following parameters as request
CreateOpportunity
CreateAccount
CreateContact
customerid
targetentityname
targetentityid
requestname
transactioncurrencyid
statuscode
subject
fullname
lastname
companyname
createdby
campaignid
But am getting Insufficient parameter error as response.
Can anybody help me out by providing the missing parameters?

In case you need to create only opportunity from your lead it's completely enough to pass next parameters to QualifyLeadRequest:
1. CreateOpportunity
2. OpportunityCurrencyId
3. OpportunityCustomerId
4. Status
5. LeadId
Please take a look at sample code below
C#:
var rmc = new RetrieveMultipleRequest()
{
Query = new QueryExpression("organization")
{
ColumnSet = new ColumnSet("basecurrencyid")
}
};
var rmc_r = (RetrieveMultipleResponse)serviceProxy.Execute(rmc);
//Qualify lead
var qlr = new QualifyLeadRequest()
{
CreateOpportunity = true,
OpportunityCurrencyId = rmc_r.EntityCollection.Entities[0].GetAttributeValue<EntityReference>("basecurrencyid"),
OpportunityCustomerId = new EntityReference("account", new Guid(<your-existing-account-guid>)),
//3 is statuscode value "Qualified" for lead entity
Status = new OptionSetValue(3),
LeadId = new EntityReference("lead", new Guid(<your-existing-account-guid>))
};
Please take a look at SOAPLogger (SDK\SampleCode\CS\Client\SOAPLogger) tool distributed with Dynamics CRM SDK to get request XML string and send as request payload from your client extensions (JavaScript).
via

Related

Entity Framework 6 - Multiple added entities may have the same primary key

I have the following code where I want to add two post entries prior to saving:
ticket.Open();
var post = new Post
{
TicketId = dto.TicketId,
PostContent = "Ticket status changed to Open",
IsAutomatic = true
};
ticket.AddPost(post);
post = new Post
{
TicketId = dto.TicketId,
PostContent = HttpUtility.HtmlEncode(dto.Comments)
};
ticket.AddPost(post);
var notification = Notification.TicketReopened(post);
_unitOfWork.Complete();
A post belongs to a ticket. A notification is for a post.
However I get the following error:
Unable to determine the principal end of the 'Notification_Post' relationship. Multiple added entities may have the same primary key.
The only way I can fix is by calling _unitOfWork.Complete() after adding the first post and then calling it again at the end.
_unitOfWork.Complete() simply does the following:
public void Complete()
{
_context.SaveChanges();
}
However I need to complete the entire transaction as a whole.
How can I fix?

How to Speed Up Contract API CustomerID Search?

I'm trying to search the existing Customers and return the CustomerID if it exists. This is the code I'm using which works:
var CustomerToFind = new Customer
{
MainContact = new Contact
{
Email = new StringSearch { Value = emailIn }
}
};
var sw = new Stopwatch();
sw.Start();
//see if any results
var result = (Customer)soapClient.Get(CustomerToFind);
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
However, I've finding it appears extremely slow to the point of being unusable. For example on the DEMO dataset, on my i7-6700k # 4GHz with 24gb ram and SSD running SQL Server 2016 Developer Edition locally a simple email search takes between 3-4seconds. However on my production dataset with 10k Customer records, it takes over 60 seconds and times out.
Is this typical using Contract based soap? Screen based soap seems much faster and almost instant. If I perform a SQL select on the database tables in Microsoft Management Studio I can also return the result instantly.
Is there a better quick way to query if a Customer with email address = "test#test.com" exists and return the Customer ID?
Try using GetList instead of Get. It's better suited for "search for smth" scenarios.
When using GetList, depending on which endpoint you're using, there are two more optimizations. In Default/5.30.001 endpoint there's a second parameter to GetList which you should set to false. In Default/6.00.001 endpoint there's no second parameter but there is additional property in the entity itself, called ReturnBehavior. Either set it to OnlySpecified and then add *Return to required fields, like this:
var CustomerToFind = new Customer
{
ReturnBehavior = ReturnBehavior.OnlySpecified,
CustomerID = new StringReturn(),
MainContact = new Contact
{
Email = new StringSearch { Value = emailIn }
}
};
or set it to OnlySystem and then use ID on returned entity to request the full entity.

Exchange Service Finditems giving 407 error

we need to search email from outlook.com and to achieve this we are using Exchange Web Service (EWS) but getting 407 error a the time of calling FindItem method of service.
Here is the code which we are working on -
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, "Test"));
//searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Body, "homecoming"));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
ItemView view = new ItemView(50);
// Identify the properties to return in the result set and the additional properties that are returned for each item.
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);
//Order the search results by the DateTimeReceived property. The sort direction is in descending order.
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);
//Set the manner by which the search filter traverses the target folder. In the following example, the search filter performs a shallow traversal. Shallow is the default option; other traversal options are Associated and SoftDeleted.
view.Traversal = ItemTraversal.Shallow;
string userEmailAddress = "username#outlook.com";
string userPassword = "OutlookPassword";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
service.Credentials = new WebCredentials(userEmailAddress, userPassword);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
Getting error at last line of code.
Can you please guide what need to be correct to resolve it?
Thank You!

How do i get user role details from WhoAmIRequest in MS CRM 2011

I am trying to find whether a user has worked on given case before in CRM 2011.
I am trying write unit test to get an user id as follows
var userid = ((WhoAmIResponse)_orgservice.Execute(new WhoAmIRequest())).UserId;
and then trying to get user details as follows:
var systemuser = _service.Retrieve(
"systemuser",
user.Id,
new ColumnSet(true)
);
My user stub as follows:
var id = new Guid("2974f072-e02a-45e8-b060-4811f24283c0");
SystemUser user = new SystemUser
{
FirstName = "FirstName_Test",
LastName = "LastName_Test",
Id = id
};
return user;
When run the test, I see different UserId, not the one I set. I am not sure what is going here. Any help will be appreciated.
Thank you
Did you try FakeXrmEasy for unit testing? No need to stub or mock anything... it's already done for you.
That's specially handy for queries, because they might have many different joins, filters, and so on, which would be hard to replicate using your own mocks from scracth. Example here
For the above example, there is also an implementation of the WhoAmIRequest which will return the user you set in the CallerId property of the context.
Here's an example.

Sending email from netsuite using freemarker template engine

Can someone help me to work my task on netsuite Sending email. The email body should be generated with the freemarker template engine using nlapiCreateTemplateRenderer. I try to used the sample on the help page in netsuite but it doesnt work. Can somebody explain or give me a example on this API.
By the way i can sent email using suitelet, my problem is the email body.
Thank you.
Provided that you have your scriptable template. This should run OK.
var emailTempId = 1; // internal id of the email template
var emailTemp = nlapiLoadRecord('emailtemplate',emailTempId);
var emailSubj = emailTemp.getFieldValue('subject');
var emailBody = emailTemp.getFieldValue('content');
var records = new Object();
records['transaction'] = '1'; //internal id of Transaction
var salesOrder = nlapiLoadRecord('salesorder', 1);
var renderer = nlapiCreateTemplateRenderer();
renderer.addRecord('transaction', salesOrder );
renderer.setTemplate(emailSubj);
renderSubj = renderer.renderToString();
renderer.setTemplate(emailBody);
renderBody = renderer.renderToString();
nlapiSendEmail(-5, 'email#domain.com', renderSubj, renderBody , null, null, records);
The new Scriptable Template that is using the FreeMarker only supports Entity, Transaction, Custom Record, Case, & Project Record. Other records might work but based on Answer Id: 32621 from the SuiteAnswers those record are the ones that will be supported.

Resources