{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":39938,"path":"platform-administration/table-administration-and-data-management/r_UIActions.md","title":"Task relationships with UI actions","bundle":null,"doc_type":null,"release":"australia","body":"\n# Task relationships with UI actions\n\nAfter defining task relationships, you can use UI Actions to define the task relationship when a new task is being created from an old task.\n\nBelow are a few examples.\n\n**Warning:** These examples may not work on all instances. They are provided as illustrative examples.\n\n## UI Actions examples\n\n**Cause an incident**\n\nThis UI Action allows the change management team to log an incident directly from the change request and records that the change caused the incident.\n\nCreate a UI Action on the Change Request \\[change\\_request\\] table and place the following into the script:\n\n```\nvar inccaus =new GlideRecord(\"incident\");\ninccaus.short_description= current.short_description;\ninccaus.comments= current.comments.getHTMLValue();\n// inccaus.parent = current.sys_id;\ninccaus.insert();\nCauIncident();\n \ngs.addInfoMessage(\"Incident \"+ inccaus.number+\" created\");\naction.setRedirectURL(current);\naction.setReturnURL(inccaus);\n \n \nfunction CauIncident(){\nvar m2m =new GlideRecord('task_rel_task');\nm2m.initialize();\nm2m.child= current.sys_id;\nm2m.parent= inccaus.sys_id;\nm2m.type.setDisplayValue(\"Caused by::Causes\");\nm2m.insert();}\n```\n\n**Cause a problem**\n\nThis UI Action allows the change management team to record a problem from a change request and record that the change caused the problem.\n\nCreate a UI Action on the Change Request \\[change\\_request\\] table and paste the following script:\n\n```\nvar probcaus =new GlideRecord(\"problem\");\nprobcaus.short_description= current.short_description;\nprobcaus.comments= current.comments.getHTMLValue();\n// probcaus.parent = current.sys_id;\nprobcaus.insert();\nCauProblem();\n \ngs.addInfoMessage(\"Problem \"+ probcaus.number+\" created\");\naction.setRedirectURL(current);\naction.setReturnURL(probcaus);\n \n \nfunction CauProblem(){\nvar m2m =new GlideRecord('task_rel_task');\nm2m.initialize();\nm2m.child= current.sys_id;\nm2m.parent= probcaus.sys_id;\nm2m.type.setDisplayValue(\"Caused by::Causes\");\nm2m.insert();}\n```\n\n**Fix a problem**\n\nThis UI Action allows a change request to be generated from a problem, recording that the change fixes the problem.\n\nCreate a UI Action on the Problem \\[problem\\] table, and paste the following code:\n\n```\nvar fixchg =new GlideRecord(\"change_request\");\nfixchg.short_description= current.short_description;\nfixchg.comments= current.comments.getHTMLValue();\n// fixchg.parent = current.sys_id;\nfixchg.insert();\nFixChange();\n \ngs.addInfoMessage(\"Change \"+ fixchg.number+\" created\");\naction.setRedirectURL(current);\naction.setReturnURL(fixchg);\n \n \nfunction FixChange(){\nvar m2m =new GlideRecord('task_rel_task');\nm2m.initialize();\nm2m.child= current.sys_id;\nm2m.parent= fixchg.sys_id;\nm2m.type.setDisplayValue(\"Fixes::Fixed by\");\nm2m.insert();}\n```\n\n**Parent Topic:**[Creating many-to-many task relations](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/table-administration-and-data-management/c_ManyToManyTaskRelations.md)\n\n"}}