Hi Dojo,
I'm looking for a script to remove resources (resource scheduling), I know we have the following script available in the SRM framework 'SRM_UnassignResourceFromBooking' from SRM 1.2.22
This script is not good for my use case because I want to know if the resource was removed or if problems occurred that resulted in that the resource couldn't removed. It should also be possible to delete resources in ongoing booking as well as past bookings
MArtijn,
Following code sample shows how to retrieve a booking and assign a resource : Silently assigning resource, profile and parameter values | DataMiner Docs
If you use a development environment (ie Visual Studio), you can see that the ServiceReservation object used in the above-mentioned example also has a 'Unassign' method that can be used to remove a resource from a booking.
Then following code sample can then do the job :
var requests = new[]
{
new AssignResourceRequest
{
NewResourceId = ResourceGuid
}
};
var sri = SrmManagers.ResourceManager.GetReservationInstance(ReservationGuid) as ServiceReservationInstance;
sri.UnassignResources(engine, requests);
Off the top of my head this is something you are looking for:
public void Run(Engine engine)
{ engine.SetFlag(RunTimeFlags.NoKeyCaching);
try
{
Guid myReservationGuid = Guid.Parse(engine.GetScriptParam("ReservationGuid").Value);
var bookingManager = new BookingManager(engine, engine.FindElement(BookingManagerElementName));
var instance = SrmManagers.ResourceManager.GetReservationInstance(myReservationGuid);
bookingManager.TryRemoveResourceAndNode(engine, ref instance, Guid.Parse(engine.GetScriptParam("ResourceGuid").Value), Convert.ToInt32(engine.GetScriptParam("NodeId").Value));
}
Hope this helps