Now lets look at one of the most useful customizes you can achieve with agent scripts. Having found an account it maybe useful to have the ability to create a new case, phone call, order etc. But when creating these new records you’ll probably want to carry forward information about the account to the new entities.
In this post I will explain how to do this.
As always, I’m going to use my fishing sample application to help explain. (sorry!) In my example I would like the ability to create a record to log details of my trips to lakes. So having viewed a lake I need an agent script that will allow me to create a trip to that lake. In the real world creating a case for an account and such like might be more typical. But the logic / approach remains the same.
The steps involved are ….
- Create a hosted control for new record.
- Create an answer to create entity.
- Create an action to create the new entity.
Step One – Create a hosted control for new record.
First of all you’ll need to create a new hosted control that will contain the new entity, so in my example I have created this control for a new fishing trip.
Notice how I have given the display name the value “New Trip([[new_fishinglake.new_name]])”, I’ve done this as the new trip won’t yet exist so I can’t use its name. But I can reference the name of the source entity. If you were creating a case for an account, for example, you mighte use something like “New Case([[account.name]])”.
Step Two – Create an answer to create entity.
I’ll assume you know how to create an agent script at this point! If not refer to the earlier posts I mentioned in my introduction.
Below you can see I have created an answer called Create Trip.
My create trip answer is shown below. Some things to notice include;
- The answer text is how the operator will see this answer described on their screens.
- The order of 1 suggested I want to see this as the top answer.
- Show tab is the hosted control I created in step one, doing this will give the new tab focus having clicked on this answer.
- The enable condition and visible condition are set to [[new.fishinglake.new_name]], I’ve done this as this option will not be presented to the operator until the lake has been saved. You wouldn’t, for example, want to allow creating cases until the required account or contact had been created.
Step Three – Create an action to create the new entity.
Now you have an agent script with an answer to create the new trip (or anything) you’ll need to add an action to the answer to create the new entity. Below you can see I have created an action call that will create my trip.
My action is shown below. A few things to note ….
- The hosted control has been set to the one created in step one.
- The action is “New_CRM_Page”.
- The data section is important. The top line “LogicalName=new_fishingtrip” defines which entity you wish to be created. Below this you can then assign values to fields on the new entity. In a more complicated real-world situation you may need to assign quite a few values here. In my example I have done the minimum of just making the new fishing trip linked to the lake I had open. Notice the syntax here. (I actually found different syntax on the Microsoft site which didn’t work!!) As the fishing lake field on the trip is a look-up I need to set the GUID and name for the field.
Having completed the steps above, when I view a lake a call script is active giving me an option to create a New Trip.
Once selected you can see that a new trip is created below and that tab has become the active tab. It might also be worth noticing that the call script that is now active is “Fishing Trip Tasks”. In my sample application I can that create details of fish caught on that trip etc. You could use this concept to give a new set of answers / tasks once a new case had been created.
I hope this post has been useful in explaining how to create entities from agent scripts.