Copy a Survey and its Questions/Choices with a form button UI Action
In another post, someone just asked how to copy a survey and all its questions and their choices. Doing that manually can be a big hassle depending on the size of the survey.If you create a form button UI Action with the following, you'll have a quick and easy way to copy a Survey Master part and parcel.Name: Copy Survey MasterTable: Survey (survey_master)Form button: checkedHint: Create a copy of this survey, including its Questions and their ChoicesScript: as follows
copySurvey();function copySurvey() { var oldID = current.sys_id.toString(); var newName = "Copy of " + current.name; current.name = newName; var newID = current.insert(); var question = new GlideRecord("survey_question_new"); question.addQuery("master", oldID); question.query(); while (question.next()) { var oldQID = question.sys_id.toString(); question.master = newID; var newQID = question.insert(); var choice = new GlideRecord("question_choice"); choice.addQuery("question", oldQID); choice.query(); while (choice.next()) { choice.question = newQID; choice.insert(); } } gs.addInfoMessage("Survey created: " + newName);}
https://www.servicenow.com/community/in-other-news/copy-a-survey-and-its-questions-choices-with-a-form-button-ui/ba-p/2277399