Can a record be created as closed?
If I create the records and then change the state, that could work, but is it possible to do it in a single step?
I am using ExecuteMultipleRequest to create Cases.
No, You have to make two request to create and resolve the case. See the examples below:
// Create an incident.
var incident = new Incident
{
CustomerId = new EntityReference(Account.EntityLogicalName, _accountId),
Title = "Sample Incident"
};
_incidentId = _serviceProxy.Create(incident);
// Create the incident's resolution.
var incidentResolution = new IncidentResolution
{
Subject = "Resolved Sample Incident",
IncidentId = new EntityReference(Incident.EntityLogicalName, _incidentId)
};
// Close the incident with the resolution.
var closeIncidentRequest = new CloseIncidentRequest
{
IncidentResolution = incidentResolution,
Status = new OptionSetValue((int)incident_statuscode.ProblemSolved)
};
_serviceProxy.Execute(closeIncidentRequest);
Ref: sdk\SampleCode\CS\BusinessDataModel\Service\CloseAnIncident.cs
You will always need two request, one to create the record and one to change the state.
You could have a plugin close the record on the create, so that way it happens in the same database transaction, but I'm guessing that it wouldn't be worth the over head.
Related
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?
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.
My objective is to respond to a picked event in an external system and mark the SalesOrder "Picked" in NetSuite and later respond to a pack event in an external system and mark the SalesOrder "Packed" in NetSuite.
I am using the code from the SuiteTalk sample application. I first get a copy of the existing ItemFulfillment record and then populate a new ItemFulfillment record.
The code works great when I respond to the pick event. Unfortunately, when I respond to the pack event, when I try to get a copy of the existing ItemFulfillment Record for the SalesOrder I get this error.
"You must have at least one valid line item for this transaction."
I assumed that NetSuite is complaining that there are no more line items to fulfill, so I tried not adding any ItemFulfillmentItem(s) when I set the status to picked, but NetSuite didn't like that either.
The only documentation that I could find referenced a task Id, /app/accounting/transactions/itemshipmanager.nl?type=pack. This approach seemed credible because when I brought up Fiddler, this is the call that it made when I click the "Mark Packed" button in the UI. However, I would prefer not to introduce a different paradigm for talking to the NetSuite server.
I have found that NetSuite will let me go straight to the Pack state if I set shipStatus and shipStatusSpecified in the ItemFulfillment.
Can I move a SalesOrder through both the picked and packed states using only NetSuite SuiteTalk?
I was going about the problem incorrectly. Instead of adding items to a new packed item fulfillment, the correct approach is to find the existing ItemFulfillment and change its status to packed.
This is the search that finds an existing ItemFulfillment for a SalesOrder:
TransactionSearch xactionSearch = new TransactionSearch
{
basic = new TransactionSearchBasic
{
type = new SearchEnumMultiSelectField
{
#operator = SearchEnumMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new System.String[]
{
"_itemFulfillment"
}
},
createdFrom = new SearchMultiSelectField
{
#operator = SearchMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new RecordRef[1]
{
new RecordRef
{
internalId = salesOrderInternalId,
type = RecordType.salesOrder,
typeSpecified = true
}
}
}
}
};
This is the code that updates the ItemFulfillment:
ItemFulfillment update = new ItemFulfillment { internalId = existing.internalId, shipStatus = status, shipStatusSpecified = true };
WriteResponse res = _service.update(update);
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
I'm associating record to some other entity using AssociateRequest.My question is how to Associate multiple records to subgrid.could you plz anyone clarify me.
Entity en=(Entity)context.InputParameters["Target"];
AssociateRequest assreq = new AssociateRequest();
assreq.Target = new EntityReference(en.LogicalName,en.Id);
assreq.RelatedEntities = new EntityReferenceCollection();
assreq.RelatedEntities.Add(new EntityReference("contact", new Guid("72C8B80B-FEF1-E311-9345-D89D67642EB0")));
assreq.Relationship = new Relationship("contact_customer_accounts");
AssociateResponse assresponse = (AssociateResponse)service.Execute(assreq);
The AssociateRequest can only be used to create a relationship between two records. If you need to associate a record multiple times, you will have to repeat the procedure for every single relationship.
You can pack the AssociateRequest's into an ExecuteMultipleRequest and save some roundtrips to the server. Please, keep in mind: the requests that are in the ExecuteMultipleRequest do not participate in the same database transaction.
OrganizationRequestCollection associateRequestCollection = new OrganizationRequestCollection();
Entity en = (Entity)context.InputParameters["Target"];
you will have to create AssociateRequest for every single
relationship and add them int associateRequestCollection object like below
AssociateRequest assreq = new AssociateRequest();
assreq.Target = new EntityReference(en.LogicalName, en.Id);
assreq.RelatedEntities = new EntityReferenceCollection();
assreq.RelatedEntities.Add(new EntityReference("contact", new Guid("72C8B80B-FEF1-E311-9345-D89D67642EB0")));
assreq.Relationship = new Relationship("contact_customer_accounts");
associateRequestCollection.Add(assreq);
//Process the Create Multiple emails against Contact Ids;
ExecuteMultipleResponse emResponses = ExecuteCRMMultipleRequest(associateRequestCollection);
private ExecuteMultipleResponse ExecuteCrmMultipleRequest(OrganizationRequestCollection associateRequestCollection)
{
ExecuteMultipleRequest emRequest = new ExecuteMultipleRequest
{
Requests = associateRequestCollection,
Settings = new ExecuteMultipleSettings
{
ContinueOnError = true,
ReturnResponses = true
}
};
return (ExecuteMultipleResponse)service.Execute(emRequest);
}