This code appears to be part of a **Microsoft Power...

August 7, 2025 at 06:33 PM

{ "type": "Foreach", "foreach": "@outputs('Get_files_(properties_only)_-_Open_Status_=_Open')?['body/value']", "actions": { "Set_variable_Job_Posting_Lookup": { "type": "SetVariable", "inputs": { "name": "JobPostingLookup", "value": "@items('Apply_to_each')?['{Name}']" }, "metadata": { "operationMetadataId": "68dd092f-d3d5-4513-81f2-daa4bc1379bc" } }, "Condition_If_Sworn": { "type": "If", "expression": { "equals": [ "@items('Apply_to_each')?['EmployeeType/Value']", "Sworn" ] }, "actions": { "Update_file_properties_-_Open_Status_=_Open": { "type": "OpenApiConnection", "inputs": { "parameters": { "dataset": "https://surreypoliceservices.sharepoint.com/sites/HRES", "table": "c3fbb747-64a3-45fa-a7c2-bb937e98a07b", "id": "@items('Apply_to_each')?['ID']", "item/Title": " ", "item/OpenStatus/Value": "Open", "item/SectionUnit/Value": "@items('Apply_to_each')?['SectionUnit/Value']", "item/JobPosting": "@variables('JobPostingLookup')", "item/JobPostingLink/Value": "Linked" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline", "connection": "shared_sharepointonline", "operationId": "PatchFileItem" } }, "metadata": { "operationMetadataId": "d7c781e3-895d-4d65-a79e-638811a087b5" } }, "Condition_HR_Posting_ID_value_null": { "type": "If", "expression": { "equals": [ "@items('Apply_to_each')?['HRPostingID']", "@null" ] }, "actions": {}, "else": { "actions": { "Get_file_properties_HR_Posting_Sworn_Posting": { "type": "OpenApiConnection", "inputs": { "parameters": { "dataset": "https://surreypoliceservices.sharepoint.com/sites/HRPostings", "table": "44a6086c-c865-41f0-a7d0-764446de67d4", "id": "@items('Apply_to_each')?['HRPostingID']" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline", "connection": "shared_sharepointonline_1", "operationId": "GetFileItem" } }, "metadata": { "operationMetadataId": "88912bbc-08b4-4ce3-ba41-3bb1b7a36b58" } }, "Update_file_properties_HR_Posting_Sworn_Posting": { "type": "OpenApiConnection", "inputs": { "parameters": { "dataset": "https://surreypoliceservices.sharepoint.com/sites/HRPostings", "table": "44a6086c-c865-41f0-a7d0-764446de67d4", "id": "@outputs('Get_file_properties_HR_Posting_Sworn_Posting')?['body/ID']", "item/OpenStatus/Value": "Open" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline", "connection": "shared_sharepointonline_1", "operationId": "PatchFileItem" } }, "runAfter": { "Get_file_properties_HR_Posting_Sworn_Posting": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "e57db9f2-e3d1-4f74-bfb8-02b9656fc5d5" } }, "Get_item_HR_Posting_SAR": { "type": "OpenApiConnection", "inputs": { "parameters": { "dataset": "https://surreypoliceservices.sharepoint.com/sites/HRPostings", "table": "dd22d208-1d0a-482f-b310-16385a471ab1", "id": "@outputs('Get_file_properties_HR_Posting_Sworn_Posting')?['body/SARLookup/Id']" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline", "connection": "shared_sharepointonline_1", "operationId": "GetItem" } }, "runAfter": { "Update_file_properties_HR_Posting_Sworn_Posting": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "5e848b5a-91dc-40da-a68e-c195e4edbbfc" } }, "Update_item_HR_Posting_SAR_Updates_to_Active": { "type": "OpenApiConnection", "inputs": { "parameters": { "dataset": "https://surreypoliceservices.sharepoint.com/sites/HRPostings", "table": "dd22d208-1d0a-482f-b310-16385a471ab1", "id": "@outputs('Get_item_HR_Posting_SAR')?['body/SectionUnit/WssId']", "item/SectionUnit/Value": "@outputs('Get_item_HR_Posting_SAR')?['body/SectionUnit/Value']", "item/PostingComments": "@variables('SARComments')", "item/ApprovalStatus/Value": "Active" }, "host": { "apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline", "connection": "shared_sharepointonline_1", "operationId": "PatchItem" } }, "runAfter": { "Set_variable_SAR_COMMENTS": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "f98fa168-2ceb-4b88-9b94-8187ad187e17" } }, "Convert_time_zone_to_Open": { "type": "Expression", "kind": "ConvertTimeZone", "inputs": { "baseTime": "@items('Apply_to_each')?['OpenDate']", "sourceTimeZone": "Pacific Standard Time", "destinationTimeZone": "Pacific Standard Time", "formatString": "MMMM dd, yyyy" }, "runAfter": { "Get_item_HR_Posting_SAR": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "fda14e4d-a34e-4bb6-ae88-66e7b6aedbe2" } }, "Set_variable_SAR_COMMENTS": { "type": "SetVariable", "inputs": { "name": "SARComments", "value": "@{outputs('Get_item_HR_Posting_SAR')?['body/PostingComments']}\n@{body('Convert_time_zone_to_Open')}: @{items('Apply_to_each')?['{Name}']} @{items('Apply_to_each')?['PostingType/Value']}Opened on Internal Job Board" }, "runAfter": { "Convert_time_zone_to_Open": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "a581276f-8b90-4335-81ba-912337005846" } } } }, "runAfter": { "Update_file_properties_-_Open_Status_=_Open": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "51d1d0e1-e0a7-4b18-835e-60ebfcddd72c" } } }, "else": { "actions": {} }, "runAfter": { "Set_variable_Job_Posting_Lookup": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "6ddee29e-6f2b-48ad-9849-0c2fdb899268" } } }, "runAfter": { "Get_files_(properties_only)_-_Open_Status_=_Open": [ "Succeeded" ] }, "metadata": { "operationMetadataId": "c484e3f4-6009-45aa-8b3c-9240ab08d705" } }

This code appears to be part of a Microsoft Power Automate workflow (previously known as Microsoft Flow) or similar low-code/no-code automation environment. Here's a detailed description of what the code accomplishes:

Overview:

The workflow processes a list of files or items retrieved from a SharePoint list where the "Open Status" is equal to "Open". For each item, it performs various checks and updates in SharePoint. The purpose of this Flow seems to handle job postings and their statuses, specifically for "Sworn" employees, and update relevant metadata or dependent entities.


Key Steps:

  1. Iterate through items ("For Each"):

    • It loops through the results of the action Get_files_(properties_only)_-_Open_Status_=_Open. The foreach statement iterates over the values in the array (body/value).
  2. Set a Variable (Set_variable_Job_Posting_Lookup):

    • A variable named JobPostingLookup is set to the value of the {Name} field for the current item being processed in the loop.
  3. Check if the Employee Type is "Sworn":

    • An If condition checks whether the EmployeeType/Value field of the current item equals "Sworn".
    • If it’s not "Sworn", no specific actions are performed.
  4. Update File Properties:

    • If the condition (EmployeeType = Sworn) is met, the workflow updates the file properties in a SharePoint list. Specifically:
      • "Open Status" is updated to "Open".
      • "JobPosting" is updated with the JobPostingLookup variable.
      • Additional metadata properties such as SectionUnit and JobPostingLink are configured.
  5. Handle Items with Null HRPostingID:

    • Another If condition checks whether the HRPostingID field of the current item is null.
    • If it's null, no further actions occur.
  6. Handle Items with Non-Null HRPostingID:

    • If HRPostingID is not null, additional actions are performed on related SharePoint items:
      • Fetches the item associated with the HRPostingID from another SharePoint list (Get_file_properties_HR_Posting_Sworn_Posting).
      • Updates the fetched item's "OpenStatus" property to "Open".
  7. Process Related "SAR" Item:

    • After updating the item with HRPostingID, the workflow looks up another related item using a SAR lookup field and retrieves its details (Get_item_HR_Posting_SAR).
  8. Update the SAR Item:

    • The "ApprovalStatus" for the SAR item is updated to "Active".
    • Additional metadata, such as "SectionUnit" and "PostingComments", is updated based on other variable values in the workflow.
  9. Convert and Format Time Zone (Optional Step):

    • The workflow converts the OpenDate field of the current item to a specific time zone (Pacific Standard Time) and formats the result (e.g., "MMMM dd, yyyy").
  10. Build "SARComments" Variable:

    • A variable named SARComments is updated with a combination of existing comments, the formatted timestamp, and some metadata describing an update about the posting being "Opened on Internal Job Board".

Summary:

The workflow automates the processing of job-related SharePoint records. Specifically:

  1. It loops through items in a SharePoint list with an "Open" status.
  2. If the item’s EmployeeType is "Sworn," it updates the record and links related job postings and metadata.
  3. It handles additional logic for related postings (e.g., HRPostingID and SAR records) by fetching, updating, and maintaining consistency in dependent SharePoint lists.
  4. It formats time zones, updates tracking variables (e.g., SARComments), and ensures proper statuses are set across relevant entities in SharePoint.

This is typically used in HR systems for job management, postings, and approvals.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node