<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create workforce assignments based on selection from feature layer in ArcGIS Workforce Questions</title>
    <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1361968#M2725</link>
    <description>&lt;P&gt;I have a script set up to create assignments, it decides if an assignment is being created based on an attribute, but not the assignment type, but in using this you could perhaps set it up so you have this section multiple times and just set the assignment type in each loop? (maybe not the most efficient, but I made it work so I'm happy with it haha)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;assignments = []
weekdays_dic ={0:'GR1', 1:'GR2',2:'GR3',3:'GR4',4:'GR5',5:'GR6', 6:'GR0'}
weekday_today = weekdays_dic[datetime.today().weekday()]
hort_garbage = project.workers.get(user_id="horticulture.garbage@moncton.ca_moncton")
robert = project.workers.get(user_id="robert.anderson@moncton.ca_moncton")
end_of_day = datetime.combine(datetime.now(), time.max)

for feature in garbage_cans:
    subarea=str(feature.attributes["SUBAREA"]).replace(" ","").split(",")
    unittype=str(feature.attributes["UNITTYPE"])
    if weekday_today in subarea and (unittype=='DOGPOLE' or unittype=='GARCAN' or unittype=='NEEDLE BOX'):
        assignments.append(
            workforce.Assignment(
                project,
                geometry=feature.geometry,
                location=feature.attributes["UNITID"],
                description=feature.attributes["ADDRQUAL"],
                priority="Medium",
                due_date=end_of_day,
                assignment_type="Empty Garbage",
                status="assigned",
                worker=hort_garbage
            )
        )
project.assignments.batch_add(assignments)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My other thought is you either need to make sure the assignment type in the layer is EXACTLY the same domain label as in your project, or you'll need to store it as the GlobalID that the assignment table stores. Or you could use the dictionary for your assignments between the two layers like I have for my days of the week?&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2023 13:12:15 GMT</pubDate>
    <dc:creator>RobertAnderson3</dc:creator>
    <dc:date>2023-12-18T13:12:15Z</dc:date>
    <item>
      <title>Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1361657#M2722</link>
      <description>&lt;P&gt;I have been attempting to create workforce assignments based on values of an existing feature layer on AGOL.&lt;/P&gt;&lt;P&gt;I followed the workflow described in this blog:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-workforce-blog/automate-workforce-with-arcgis-api-for-python/ba-p/887570" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-workforce-blog/automate-workforce-with-arcgis-api-for-python/ba-p/887570&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The section of code where assignments are supposed to be created is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;assignments = []&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;for feature in pr:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;assignments.append(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;workforce.Assignment(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;project,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;geometry=feature.geometry,&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;location=feature.attributes["locdesc"],&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;description=feature.attributes["details"],&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;assignment_type="Inspect Trees",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;status="unassigned"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;project.assignments.batch_add(assignments)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;In the code from shown above I changed &lt;STRONG&gt;assignment_type="Inspect Trees"]&amp;nbsp;&lt;/STRONG&gt;to&amp;nbsp;&lt;STRONG&gt;assignment_type=feature.attributes["AssignType"]&amp;nbsp;&lt;/STRONG&gt;in hopes I could take values from my existing feature layer that are stored in the AssignType field and create assignments based on those. I made sure the assignment types matched exactly to what are stored in my feature layer (example 1=Abandoned Car in both the workforce layer and my feature layer).&lt;/P&gt;&lt;P&gt;However, when I try to run the block of code I get the following error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ValidationError&lt;/SPAN&gt;                           Traceback (most recent call last)
&lt;SPAN class=""&gt;/tmp/ipykernel_28/1267473057.py&lt;/SPAN&gt; in &lt;SPAN class=""&gt;&amp;lt;cell line: 2&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt;
&lt;SPAN class=""&gt;      2&lt;/SPAN&gt; &lt;SPAN class=""&gt;for&lt;/SPAN&gt; feature &lt;SPAN class=""&gt;in&lt;/SPAN&gt; pr&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;      3&lt;/SPAN&gt;     assignments.append(
&lt;SPAN class=""&gt;----&amp;gt; 4&lt;/SPAN&gt;&lt;SPAN class=""&gt;         workforce.Assignment(&lt;/SPAN&gt;&lt;SPAN class=""&gt;      5&lt;/SPAN&gt;             project&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
&lt;SPAN class=""&gt;      6&lt;/SPAN&gt;             geometry&lt;SPAN class=""&gt;=&lt;/SPAN&gt;feature&lt;SPAN class=""&gt;.&lt;/SPAN&gt;geometry&lt;SPAN class=""&gt;,&lt;/SPAN&gt;

&lt;SPAN class=""&gt;/opt/conda/lib/python3.9/site-packages/arcgis/apps/workforce/assignment.py&lt;/SPAN&gt; in &lt;SPAN class=""&gt;__init__&lt;/SPAN&gt;&lt;SPAN class=""&gt;(self, project, feature, geometry, assignment_type, assigned_date, assignment_read, completed_date, declined_comment, declined_date, description, dispatcher, due_date, in_progress_date, location, notes, paused_date, priority, status, work_order_id, worker)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    188&lt;/SPAN&gt;             self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;status &lt;SPAN class=""&gt;=&lt;/SPAN&gt; status
&lt;SPAN class=""&gt;    189&lt;/SPAN&gt;             self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;work_order_id &lt;SPAN class=""&gt;=&lt;/SPAN&gt; work_order_id
&lt;SPAN class=""&gt;--&amp;gt; 190&lt;/SPAN&gt;             self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;assignment_type &lt;SPAN class=""&gt;=&lt;/SPAN&gt; assignment_type
&lt;SPAN class=""&gt;    191&lt;/SPAN&gt;             self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;dispatcher &lt;SPAN class=""&gt;=&lt;/SPAN&gt; dispatcher
&lt;SPAN class=""&gt;    192&lt;/SPAN&gt;             self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;worker &lt;SPAN class=""&gt;=&lt;/SPAN&gt; worker

&lt;SPAN class=""&gt;/opt/conda/lib/python3.9/site-packages/arcgis/apps/workforce/assignment.py&lt;/SPAN&gt; in &lt;SPAN class=""&gt;assignment_type&lt;/SPAN&gt;&lt;SPAN class=""&gt;(self, value)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    380&lt;/SPAN&gt;                 self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;_assignment_type &lt;SPAN class=""&gt;=&lt;/SPAN&gt; self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;project&lt;SPAN class=""&gt;.&lt;/SPAN&gt;_cached_assignment_types&lt;SPAN class=""&gt;[&lt;/SPAN&gt;value&lt;SPAN class=""&gt;]&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    381&lt;/SPAN&gt;             &lt;SPAN class=""&gt;else&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;--&amp;gt; 382&lt;/SPAN&gt;                 &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; ValidationError&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"Invalid Assignment Type"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; self&lt;SPAN class=""&gt;)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    383&lt;/SPAN&gt;         &lt;SPAN class=""&gt;elif&lt;/SPAN&gt; isinstance&lt;SPAN class=""&gt;(&lt;/SPAN&gt;value&lt;SPAN class=""&gt;,&lt;/SPAN&gt; str&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    384&lt;/SPAN&gt;             &lt;SPAN class=""&gt;for&lt;/SPAN&gt; at &lt;SPAN class=""&gt;in&lt;/SPAN&gt; self&lt;SPAN class=""&gt;.&lt;/SPAN&gt;project&lt;SPAN class=""&gt;.&lt;/SPAN&gt;_cached_assignment_types&lt;SPAN class=""&gt;.&lt;/SPAN&gt;values&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;

&lt;SPAN class=""&gt;ValidationError&lt;/SPAN&gt;: Invalid Assignment Type&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;When I hard code it assignments are created without any issue but instead of creating assignments based on what value is stored in my feature classes, I get assignments that are all the same.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight would be greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Dec 2023 22:05:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1361657#M2722</guid>
      <dc:creator>AriLukas</dc:creator>
      <dc:date>2023-12-15T22:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1361968#M2725</link>
      <description>&lt;P&gt;I have a script set up to create assignments, it decides if an assignment is being created based on an attribute, but not the assignment type, but in using this you could perhaps set it up so you have this section multiple times and just set the assignment type in each loop? (maybe not the most efficient, but I made it work so I'm happy with it haha)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;assignments = []
weekdays_dic ={0:'GR1', 1:'GR2',2:'GR3',3:'GR4',4:'GR5',5:'GR6', 6:'GR0'}
weekday_today = weekdays_dic[datetime.today().weekday()]
hort_garbage = project.workers.get(user_id="horticulture.garbage@moncton.ca_moncton")
robert = project.workers.get(user_id="robert.anderson@moncton.ca_moncton")
end_of_day = datetime.combine(datetime.now(), time.max)

for feature in garbage_cans:
    subarea=str(feature.attributes["SUBAREA"]).replace(" ","").split(",")
    unittype=str(feature.attributes["UNITTYPE"])
    if weekday_today in subarea and (unittype=='DOGPOLE' or unittype=='GARCAN' or unittype=='NEEDLE BOX'):
        assignments.append(
            workforce.Assignment(
                project,
                geometry=feature.geometry,
                location=feature.attributes["UNITID"],
                description=feature.attributes["ADDRQUAL"],
                priority="Medium",
                due_date=end_of_day,
                assignment_type="Empty Garbage",
                status="assigned",
                worker=hort_garbage
            )
        )
project.assignments.batch_add(assignments)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My other thought is you either need to make sure the assignment type in the layer is EXACTLY the same domain label as in your project, or you'll need to store it as the GlobalID that the assignment table stores. Or you could use the dictionary for your assignments between the two layers like I have for my days of the week?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 13:12:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1361968#M2725</guid>
      <dc:creator>RobertAnderson3</dc:creator>
      <dc:date>2023-12-18T13:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362172#M2726</link>
      <description>&lt;P&gt;I created a field in my hosted feature service that matches exactly to assignment type in workforce but had no luck. Since there are only about 10 items i would need to have assignments created for so I don't think it would be a huge lift to copy and paste this section of code 10 times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was looking over your code and was wondering where and at what point do you define &lt;STRONG&gt;garbage_cans&lt;/STRONG&gt;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you again for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 18:59:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362172#M2726</guid>
      <dc:creator>AriLukas</dc:creator>
      <dc:date>2023-12-18T18:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362198#M2727</link>
      <description>&lt;P&gt;No problem! And hmm interesting, using the globalID style or the name? Because in my loop I have it set by the name of the assignment type, they seem to work interchangeably, whether that's best practice or not I'm not sure though haha.&lt;/P&gt;&lt;P&gt;I define&amp;nbsp;&lt;STRONG&gt;garbage_cans&amp;nbsp;&lt;/STRONG&gt;in an earlier cell, it's the layer I'm working with. With itemID actually being the ID of the item in ArcGIS Online.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;layer = gis.content.get("itemID").layers[1]
garbage_cans = layer.query('1=1', out_sr=3857).features&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 19:36:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362198#M2727</guid>
      <dc:creator>RobertAnderson3</dc:creator>
      <dc:date>2023-12-18T19:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362245#M2728</link>
      <description>&lt;P&gt;ahh i forgot to run that cell first! Your workflow worked like a charm. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 20:13:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362245#M2728</guid>
      <dc:creator>AriLukas</dc:creator>
      <dc:date>2023-12-18T20:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create workforce assignments based on selection from feature layer</title>
      <link>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362755#M2729</link>
      <description>&lt;P&gt;I'm glad to hear it worked, no problem at all!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 19:33:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-workforce-questions/create-workforce-assignments-based-on-selection/m-p/1362755#M2729</guid>
      <dc:creator>RobertAnderson3</dc:creator>
      <dc:date>2023-12-19T19:33:55Z</dc:date>
    </item>
  </channel>
</rss>

