{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":14659,"path":"field-service-management/field-service-manager-workforce/set-agent-schedule-preferences.md","title":"Allow agents to start traveling before their scheduled work hours","bundle":null,"doc_type":null,"release":"australia","body":"\n# Allow agents to start traveling before their scheduled work hours\n\nSupport flexible work types by allowing agents to start traveling before their scheduled work hours. For example, you may want to add travel time outside of an agent's scheduled work hours in case bad weather suddenly increases travel time.\n\n## Before you begin\n\nIf you are an administrator, you can run a script and add travel time outside of work hours for all users.\n\nRole required: wm\\_dispatcher, wm\\_manager, wm\\_admin, or admin\n\n## Procedure\n\n1.  Navigate to **All** &gt; **Field Service**.\n\n2.  Do one of the following actions:\n\n    -   If you are a dispatcher, go to **Dispatching** &gt; **My Agents**.\n    -   If you are a manager, go to **Manager** &gt; **My Team**.\n3.  Select a user profile.\n\n4.  To add or update user records, do one of the following.\n\n<table id=\"choicetable_pnx_tzm_vgb\"><thead><tr><th align=\"left\" id=\"d88298e126\">\n\nOption\n\n</th><th align=\"left\" id=\"d88298e129\">\n\nDescription\n\n</th></tr></thead><tbody><tr><td id=\"d88298e135\">\n\n**Add a new record for this user**\n\n</td><td>\n\n1.  Click the **Work Parameters** tab.\n2.  Click **New**.\n3.  Click the **Travel outside of work hours** drop-down menu.\n4.  Click **Yes**\n5.  Click **Submit**.\n\n\n</td></tr><tr><td id=\"d88298e176\">\n\n**Updated an existing record**\n\n</td><td>\n\n1.  Click the **Work Parameters** tab.\n2.  Double-click the **Travel outside of work hours** column.\n3.  Click the new parameter.\n4.  Click **Save \\(Enter\\)**.\n\n\n</td></tr></tbody>\n</table>5.  To add travel time as work hours for all users, do the following:\n\n    1.  Navigate to **System Definition** &gt; **Scripts - Background**\n\n    2.  In the **Run Script** window, add the script to include travel time as work hours for all users.\n\n<table id=\"table_jsx_f4c_nsb\"><thead><tr><th>\n\nOption\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nAdd travel time as work hours for all users\n\n</td><td>\n\n1.  Add this script:\n\n    ```\ncreateWorkParamsForAllAgents(\"yes\");\n\nfunction createWorkParamsForAllAgents(travelOutsideWorkHours) {\n\tvar gr = new GlideRecord(\"sys_user_has_role\");\n\tgr.addEncodedQuery(\"role=26c324ba1b32200096f9fbcd2c0713c2\"); // fetching users having wm_agent role\n\tgr.query();\n\tgs.info(\"total work agents found: \"+gr.getRowCount());\n\tvar agentWorkParameter = {};\n\t\t\n\t\twhile (gr.next()) {\n\t\t\tvar userId = gr.getValue(\"user\");\n\t\t\tif (!agentWorkParameter[userId]) {\n\t\t\t\tvar wp = new GlideRecord(\"wm_agent_work_configuration\");\n\t\t\t\twp.initialize();\n\t\t\t\twp.setValue(\"user\",userId);\n\t\t\t\twp.setValue(\"travel_outside_of_work_hours\", travelOutsideWorkHours); // setting default value for travel_outside_of_work_hours\n\t\t\t\twp.insert();\n\t\t\t\tagentWorkParameter[userId] = true;\n\t\t\t}\n\t\t}\n\t}\n    ```\n\n2.  Click **Run Script**.\n\n\n</td></tr><tr><td>\n\nUpdate travel time as work hours for all users\n\n</td><td>\n\n1.  Add this script:\n\n    ```\nupdateWorkParamsForAgents(\"yes\");  // param1: default travel outside work hours value\n\nfunction updateWorkParamsForAgents(travelOutsideWorkHours) {\n\tvar gr = new GlideRecord(\"wm_agent_work_configuration\");\n\tgr.query();\n\tgs.info(\"total agent work parameters found: \"+gr.getRowCount());\n\tvar updateCount = 0;\n\t\n\twhile (gr.next()) {\n\t\tvar canTravelOutside = gr.getValue(\"travel_outside_of_work_hours\");\n\t\tif ( canTravelOutside != travelOutsideWorkHours) {\n\t\t\tgr.setValue(\"travel_outside_of_work_hours\", travelOutsideWorkHours);\n\t\t\tif (gr.update())\n\t\t\t\tupdateCount ++;\n\t\t}\n\t}\n\tgs.info(\"total agent work parameters updated: \"+updateCount);\n}\n    ```\n\n2.  Click **Run Script**.\n\n\n</td></tr></tbody>\n</table>\n"}}