CapaJC
ServiceNow Employee
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
10-17-2012
09:43 AM
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 Master
Table: Survey (survey_master)
Form button: checked
Hint: Create a copy of this survey, including its Questions and their Choices
Script: 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);
}
- 836 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.