Hi Team,
Does anyone know if there is a way to access the name of the method being called inside code in a BPM?
Reason is I want to write code I can use in multiple BO’s for Update and Delete to track row changes but I don’t want to write a BPM for each BO just a generic one I can copy and paste and will work.
I could look at the row update/delete flag on the table being sent but accessing the method directive would be more reliable as most bo’s have multiple update rows.
This should fix you up, at least until @josecgomez comes along and says there is something easier
This is verbose, so people can see how it can be done. Clean up as needed.
string messageText = "";
//Your information is here:
var thisAssembly = this.GetType().Assembly;
//This next bit can obviosuly be done a bit different, I broke it out like this to show how to parse it.
//Ice.BO.DynamicQuery.GetList,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null
string assemblyFullNameUnfiltered = thisAssembly.FullName;
//Ice.BO.DynamicQuery.GetList
string assemblyFullNameFiltered = assemblyFullNameUnfiltered.Split(",")[0]; //Split on comma, get first item
//.GetList
string boMethod = assemblyFullNameFiltered.Substring(assemblyFullNameFiltered.LastIndexOf(".")); //Get the last index of the dot, get text from there, leave dot on
//Ice.BO.DynamicQuery
string businessObject = assemblyFullNameFiltered.TrimEnd(boMethod.ToCharArray()); //remove the method text from the end, the dot is still on so it pulls it all off
//GetList
boMethod = boMethod.TrimStart('.'); //Remove leading dot
messageText += $"Assembly Full Name Complete: {assemblyFullNameUnfiltered}\n";
messageText += $"Assembly Full Name Filtered: {assemblyFullNameFiltered}\n";
messageText += $"BO: {businessObject}\n";
messageText += $"BO Method: {boMethod}\n";
messageText += $"BO Method Type: {this.TypeName}\n";
this.PublishInfoMessage(messageText, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
Output:
Assembly Full Name Complete: Ice.BO.DynamicQuery.GetList,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null
Assembly Full Name Filtered: Ice.BO.DynamicQuery.GetList
BO: Ice.BO.DynamicQuery
BO Method: GetList
BO Method Type: PreProcessing
Here is another way, query the Db with LINQ for the directive ID:
I did not test speed on any of these methods.
(Also verbose )
string messageText = "";
//Query Db for this directive ID (this.Id)
BpDirective thisBPDirective = Db.BpDirective.Where(bpd => bpd.DirectiveID == this.Id).First();
//Get Assembly Name
string assemblyFullName = thisBPDirective.BpMethodCode;
//.GetList
string boMethod = assemblyFullName.Substring(assemblyFullName.LastIndexOf(".")); //Get the last index of the dot, get text from there, leave dot on
//Ice.BO.DynamicQuery
string businessObject = assemblyFullName.TrimEnd(boMethod.ToCharArray()); //remove the method text from the end, the dot is still on so it pulls it all off
//GetList
boMethod = boMethod.TrimStart('.'); //Remove leading dot
messageText += $"Assembly Full Name: {assemblyFullName}\n";
messageText += $"BO: {businessObject}\n";
messageText += $"BO Method: {boMethod}\n";
messageText += $"BO Method Type: {this.TypeName}\n";
this.PublishInfoMessage(messageText, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
Output:
Assembly Full Name: Ice.BO.DynamicQuery.GetList
BO: Ice.BO.DynamicQuery
BO Method: GetList
BO Method Type: PreProcessing
Last one, I promise
I’m bored and I don’t want to vacuum the pool, it’s HOT outside!
Edit: I did clean my pool, swam, and grilled food. Very productive day.
Not sure how I don’t look like a lobster.
Query the Business Object with the ID of the directive you are in.
Again, no speed tests done.
string messageText = "";
//Query the business object for this directive ID (this.Id)
//This is already referenced in all BP Methods
BpDirectiveRow thisBpDirectiveRow = null;
CallService<Ice.Contracts.BpMethodSvcContract>(bpMethods =>
{
bool morePages = false;
thisBpDirectiveRow = bpMethods.GetRows("", "", $"DirectiveID = '{this.Id.ToString()}'", 0, 0, out morePages).BpDirective.First();
});
//Get Assembly Name
string assemblyFullName = thisBpDirectiveRow.BpMethodCode;
//.GetList
string boMethod = assemblyFullName.Substring(assemblyFullName.LastIndexOf(".")); //Get the last index of the dot, get text from there, leave dot on
//Ice.BO.DynamicQuery
string businessObject = assemblyFullName.TrimEnd(boMethod.ToCharArray()); //remove the method text from the end, the dot is still on so it pulls it all off
//GetList
boMethod = boMethod.TrimStart('.'); //Remove leading dot
messageText += $"Assembly Full Name: {assemblyFullName}\n";
messageText += $"BO: {businessObject}\n";
messageText += $"BO Method: {boMethod}\n";
messageText += $"BO Method Type: {this.TypeName}\n";
this.PublishInfoMessage(messageText, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
Assembly Full Name: Ice.BO.DynamicQuery.GetList
BO: Ice.BO.DynamicQuery
BO Method: GetList
BO Method Type: PreProcessing