Hoppa till huvudinnehållet

'For Each' Activity in Workflow

Kommentarer

1 kommentar

  • Permanently deleted user
    Hey Lisa,

     

    When you're submitting new information to the database in the SQLNonQuery part of your workflow, your @p_id parameter is only getting the OBJECTID from the first feature in your feature set because you are referencing Features(0) which is the first index position of the FeatureSet collection. This is probably why the workflow works as expected for one segment but not many.  CInt(queryResult.Features(0).Attributes("OBJECTID"))

    You can access all of the OBJECTIDs for your feature set in a few different ways. The first is to use a ForEach<Graphic> activity with your queryResult variable as the values input. This will allow you to iterate through all of the features in the collection. During a ForEach loop, each individual item in a collection is represented by a shared variable name which exists in the scope of the ForEach sequence and that variable is updated with new item values for each subsequent iteration.

    So for example, if the input boxes for the ForEach activity read like this, "Foreach RoadSegment in queryResult"  (RoadSegment could also be whatever name you feel like entering) you could perhaps put the SQL activity inside of the ForEach sequence and set the @p_id parameter to 

    CInt(RoadSegment.Attributes("OBJECTID"))

    This would generate repeated SQL updates for each individual feature in the queryResult FeatureSet and the @p_id value would change each time to reflect the OBJECTIDs being iterated through.

     

    Bear in mind that it might be a better idea to try to craft a single SQL statement which updates all of the rows in question to reduce the load on your database. You could for example use this same type of ForEach logic to create a dictionary with your parameters and then iteratively build up a SQL command statment with additional VALUE arguments to reflect each OBJECTID and then run the SQLNoQuery activity outside of the ForEach loop with your dictionary and Command variables as input. 

    The other way to get the OBJECTIDs is to use the GetAttributeValues<T> activity. This returns a typed list of attributes values for all of the features in a feature set. You can use this list in a ForEach activity to run repeated SQL updates or build a single SQL statement as mentioned above.

     

    Hope this helps you get on the right path. Good luck!
    0

Du måste logga in om du vill lämna en kommentar.