Add a Requested Task for each HOA/HMC Contact

Questions about and code samples for automation process code snippets within Select.
Post Reply
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Add a Requested Task for each HOA/HMC Contact

Post by B_Hinote »

I was asked to add a Requested Task for every HOA/HMC Contact that gets added to the order. It was indicated that this could only be done using code snippets, as the native functions will only trigger once.

I created the following snippet to qualify when the HOA/HMC Contacts exceed the number of Requested Tasks. (I am sure there is probably a better way, but it works.)

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *

def AddTask():
taskCount=0
contactCount=0
for task in Context.RequestedTasks:
Codes = ['HOA']
if task.Code.upper() in Codes:
taskCount=taskCount+1

for cont in Context.Contacts:
Types = ['HOA', 'HMC']
if cont.Code[:3] in Types:
contactCount=contactCount+1

if contactCount > taskCount:
return True
else:
return False

AddTask()


The problem I am having is that this only triggers once, regardless of the difference between Contacts and Tasks.

In this case, I assume that I will also need to use a Code Snippet to Add the Task x times based on the difference. I believe that I saw an example that uses a snippet to add a task, however, I believe it hardcodes each of the fields instead of assigning the values based on information pulled from the Lookup Tables.

Is there a way and/or any examples that might show me how to add a task based on the values defined in the Requested Task Lookup Table? (i.e. Similar to what Automation does when you add a task with only the Task Code and Task Name provided).

Thank you for any assistance you may provide.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Add a Requested Task for each HOA/HMC Contact

Post by BobRichards »

When you create the Automation Process with the wizard, what are you using for the "When" setting? First time an order is saved or Every time?

By the way, I imagine that it is an artifact of your earlier testing, but you don't need the slice notation in "cont.Code[:3]" since you are comparing against the entire string - just "cont.Code".
Bob Richards, Senior Software Developer, SoftPro
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Re: Add a Requested Task for each HOA/HMC Contact

Post by B_Hinote »

Thank you for your response.

I have used both "First Time" as well as "Every Time". It is currently set to "Every Time" because when it was set to "First Time" it only seemed to fire once regardless of adding Subsequent HOA/HMC Contacts during subsequent saves of the order.

I will try changing cont.Code[:3] back to just cont.Code, but I seem to recall having issues with cont.Code matching with 'HOA' or 'HMC' when the cont.Code contained HOA2, HMC3, etc... The "Code" assigned to each contact is incremented beyond the first entry, so I believe that HOA2, HOA3, HOA4 would not match Types without using the first three characters.

The code snippet appears to be firing when it sees a difference between the number of HOA/HMC Contact, with Names, and the number of "HOA" tasks that have been added.

The main problem I am now facing is how to dynamically add tasks to the order that are based on the values pulled from the Lookup Table, rather than being hardcoded in the snippet. (Similar to what Automation does when I only identify the lookupCode and Description.) I think I could use the current comparison logic to identify how many tasks need to be added, but I do not want to hard code each field of the task. I want to pull the current values from the Lookup table.

Thank you.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Add a Requested Task for each HOA/HMC Contact

Post by BobRichards »

No - you are right about the Code potentially having a number after the three digits. Leave that alone.

Also:
  • "First Time" means the very first time the order is saved (that will only ever occur once in the lifetime of an order) and never again.
  • "Every Time" means the first time the order is saved and for every save in the future.
If you search the forums (with the search box in the corner), you will find examples of working with tasks. See Add Checklist task based on Requested Task Name for an example. You can also search for examples of how to query the lookup tables.
Bob Richards, Senior Software Developer, SoftPro
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Re: Add a Requested Task for each HOA/HMC Contact

Post by B_Hinote »

Mr. Righards,

Obviously, you are the expert so I do not mean any offense, but I have found the "First Time" actually works a bit different.

I too thought that "First Time" meant that the Process would only fire "on the first save attempt of the order" and thought this made no sense what so ever as SoftPro has a Profile setting that forces a save before a user even has a chance to touch the order when it is being created.

However, I have found this assumption was wrong and that "First Time" actually means that it will only fire the "First Time the Conditions are met" for the Process. (i.e. You can save the order 100 times without the condition being met, but on the 101st save if the conditions are met the Process "Does Fire" and will then never fire again for the same process.

As for my question about how to use the Lookup Table to dynamically load a task, I realize that you are not intended to be an ad-hoc programmer for less experienced people flagrant abusing the forum looking for handouts but this was not my intent. I was simply looking to see if this was even possible and if there happened to be any basic examples/concepts that I could digest and possibly build from.

Before I even posed the question, I did search the forums and believe I found examples of how to add Hardcoded Tasks similar to what Workflow does. However, I do not recall that I found any examples or confirmation that Automation and IronPython code could even access the content of a Lookup Tables to be used in the output. I would think that I could use Automation to assign orders to Workflow, but as I recall I was told this coudl not be done either. if I missed finding an example of this, then that is my bad and I will look again.

I am taking your response as confirmation that Automation Processes using IronPython Code can, in fact, access Lookup Table Values and use these values to dynamically create tasks.

I will look to see if there is a non-python example that I can make work as python code.

Brian
Pradeepa
Posts: 37
Joined: Fri Oct 03, 2008 1:22 pm

Re: Add a Requested Task for each HOA/HMC Contact

Post by Pradeepa »

Do you know which lookup entry to pull? Or do you need to inspect the values in your lookup table?

For example, if your lookup table is based on Code, and you know you want to always pull the "ABC" entry on your lookup table, you just have to set the code property on the task to "ABC". That will automatically do a lookup operation and populate remaining fields based on the lookup table.

Please let me know if this is not the case and you do need to inspect all the values in the lookup table.

Thank you!
Pradeepa.
Pradeepa Chandramohan
Software Engineer
SoftPro
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Re: Add a Requested Task for each HOA/HMC Contact

Post by B_Hinote »

Pradeepa,
Thank you for your response.
That is exactly what I needed. I wanted to use the Lookup Table Fields for a given code.
This issue is solved.
Regards,
Brian
Post Reply