This was something they told me couldn't be done, was not possible & no one had done! I am so very excited to report that it can be done, it is possible & I have now successfully done! Actually loooking at it now it is even simple... why did it take me so long to get right???
Senario:
Add A service activity as part of a workflow assembly that creates a service Activity for a booked training session when the training session is created in CRM and adds more than one resource (training room & trainer which are GUIDs passed to workflow dll) to the resources collection via the CRM Webservices/SDK :
Set your CRM connections & credentials as per usual
...
Dim myappoint As New serviceappointment
Dim party1 As activityparty = New activityparty
party1.partyid = New Lookup
party1.partyid.type = EntityName.systemuser.ToString() 'note type here is user!
party1.partyid.Value = New Guid(Trainer.ToString)
Dim party2 As activityparty = New activityparty
party2.partyid = New Lookup
party2.partyid.type = EntityName.equipment.ToString() 'note type here is equipment!
party2.partyid.Value = New Guid(Facility.ToString)
myappoint.resources = New activityparty() {party1, party2}
...
set the rest of your service activity fields taking care to get all required fields such as scheduled dates & service type
....
Dim NewId As Guid = crmservice.Create(myappoint)
It is really that easy! :)
Make sure you catch any errors of the Web.Services.Protocols.SoapException exception as it makes the workflows somewhat easier to debug.
When the workflow runs, it adds the array of resources to the service activity as per the attached screenshot example:





4 comments:
Thanks! This post helped me out!
Hi Catherine,
Great Post! Currently, I am designing a web app, so customers can register for a service activity. I am having problems adding multiple contacts to the customers lookup. Here is my code:
Dim app As serviceappointment = New serviceappointment
Dim actparty As New activityparty
actparty.partyid = New Lookup()
actparty.partyid.type = EntityName.contact.ToString()actparty.partyid.Value =contactGuid
app.customers = New activityparty() {actparty}
Dim activityGuid As Guid = New Guid("6b8fec44-9164-dd11-97e4-0016355d9f60")
app.activityid = New Key()
app.activityid.Value =activityGuid
Service.Update(app)
Hi Jeremy,
Looking at your code, you are only adding one party?
If you see in my example I use Party1 & Party2. So the code looks like its duplicated, but I am declareing each party individually.
Then, in the line:
myappoint.resources = New activityparty() {party1, party2}
See how party1 & party2 are passed as array members to the resources property? This is where the magic needs to be to add multiples! :)
Hope that helps,
Catehrine
Hi Catherine,
You have been a big help!
So, I was wondering if you could tell me how to trigger the recalculate function within the sales module. I am developing a shopping cart type application using the dynamic entity model. I can successfully add products to an invoice, but can't calculate the total. Any help would be appreciated. Thank you again!
Post a Comment