Update

Description

Update the SurveySchema

See the rules in the documentation for Filters to understand what changes are legal changed depending on Filter used
Signature
void Update(string key, string projectId, SurveySchema schema)

Parameters

Name Data Type Description

key

string required

The authentication key

projectId

string required

ID of the project

schema

SurveySchema required

TranslationXML document

Response

Data Type Description

Example

var SurveyDesign = new SurveyDesignSoapClient();

//***************************************************
//
// Retrieve, change and update ProjectInfo
//
//***************************************************

// Add a normal project (false = not a panel)
// projectID will be set to the new projectnumber
string projectID = SurveyDesign.AddProject(key,false);

// Get the project information (only projectnumber, build and
// default language is set
SurveySchema def = SurveyDesign.GetProjectInfo(key,projectID);

// Get ProjectInfo
ProjectInfo projectInfo = (ProjectInfo)def.Root.Nodes.GetValue(0);

// Check that we got it
if (projectInfo==null)
	throwError();

// Change ProjectInfo
projectInfo.Description = "The first project made by use of the API";

// Suppose that default language is English (9), make a title
LanguageString newTitle = SurveyDesignUtil.NewLanguageString("My new Title",9);

// Add the title to projectInfo
ArrayList titles = new ArrayList((Array)projectInfo.Titles);
titles.Add(newTitle);
projectInfo.Titles = (LanguageString[])titles.ToArray(typeof(LanguageString));

// Set name of the project
projectInfo.Name = "API-made project";

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Retrieve, change and update Quota
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Get Quota named quota1, projectspecific to enable update
SurveySchema def = SurveyDesign.GetQuota(key,projectID,"quota1",true);

// Get the quota
Quota quota = (Quota)def.Root.Nodes.GetValue(0);

// Check that the quota exists
if (quota==null)
	throwError();

// Change quota name
quota.Name = "NewQuotaName";

// Change quota emailaddress
quota.EmailAddress = "dummy@dummy.dummy";

// Create a new reference to an existing SingleQuestion called s1
FormReference formReference = SurveyDesignUtil.NewFormReference("s1");

// Add the reference to the quota
ArrayList forms = new ArrayList((Array)quota.Forms);
forms.Add(formReference);
quota.Forms = (FormReference[])forms.ToArray(typeof(FormReference));

// Update the quota
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get all quotas, delete one and update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Get all Quotas, projectspecific to enable update
SurveySchema def = SurveyDesign.GetQuotas(key,projectID,true);

// Remove the last quota if it exists
ArrayList quotas = new ArrayList((Array)def.Root.Nodes);
if (quotas.Count > 0)
{
	quotas.RemoveAt(quotas.Count-1);
	def.Root.Nodes = (Quota[])quotas.ToArray(typeof(Quota));
}

// Update the quota
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Retrieve, change and update PredefinedList
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Create a ReadFilterSimple
// Retrieve all languages
// Set references to other PredefinedLists as reference and not expanded
// Enable update
ReadFilterSimple readFilterSimple =
	SurveyDesignUtil.NewReadFilterSimple(true,false,true);

// Get the predefined list named "a-g"
SurveySchema def =
	SurveyDesign.GetPredefinedList(key,projectID,"a-g",readFilterSimple);

// Check that we got a reply
if (def.Root.Nodes.Length == 0)
	throwError();

// Get the predefined list
PredefinedList predefinedList =
	(PredefinedList)def.Root.Nodes.GetValue(0);

// Make changes

// Add a new Answer
Answer newAnswer = SurveyDesignUtil.NewAnswer("BMW");

// Give values to the new answer
AnswerText answerText =
	SurveyDesignUtil.NewAnswerText("BMW",9);

ArrayList texts = new ArrayList();
texts.Add(answerText);
newAnswer.Texts = (AnswerText[])texts.ToArray(typeof(AnswerText));

// Add new answer to answerlist
ArrayList answers = new ArrayList((Array)predefinedList.Answers);
answers.Add(newAnswer);
predefinedList.Answers = (AnswerBase[])answers.ToArray(typeof(AnswerBase));

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get all predefined lists, Add predefined list, Update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Create ReadFilter
ReadFilterSimple readFilterSimple =
	SurveyDesignUtil.NewReadFilterSimple(false,false,true);

// Get all PredefinedLists, projectspecific to enable update
SurveySchema def =
	SurveyDesign.GetPredefinedLists(key,projectID,readFilterSimple);

// Create new PredefinedList
PredefinedList newPredefinedList = SurveyDesignUtil.NewPredefinedList("Gender");

// Create new answers
Answer answer1 = SurveyDesignUtil.NewAnswer("M");
Answer answer2 = SurveyDesignUtil.NewAnswer("F");

// Create new answertexts
AnswerText answerText1 =
	SurveyDesignUtil.NewAnswerText("Male",9);

AnswerText answerText2 =
	SurveyDesignUtil.NewAnswerText("Female",9);

// Add answertexts to answers
ArrayList texts1 = new ArrayList();
texts1.Add(answerText1);
answer1.Texts = (AnswerText[])texts1.ToArray(typeof(AnswerText));

ArrayList texts2 = new ArrayList();
texts2.Add(answerText2);
answer2.Texts = (AnswerText[])texts2.ToArray(typeof(AnswerText));

// Add new answers to PredefinedList
ArrayList answers = new ArrayList();
answers.Add(answer1);
answers.Add(answer2);
newPredefinedList.Answers = (Answer[])answers.ToArray(typeof(Answer));

// Add PredefinedList to PredefinedList-collection
ArrayList predefinedLists = new ArrayList((Array)def.Root.Nodes);
predefinedLists.Add(newPredefinedList);
def.Root.Nodes = (PredefinedList[])predefinedLists.ToArray(typeof(PredefinedList));

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get the loopstructure, pick one loop,
// get all subforms and change their name, finally update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Get loopstructure
SurveySchema def = SurveyDesign.GetLoopStructure(key,projectID,SchemaSourceType.Design);

// Check that we got at least one loop
if (def.Root.Nodes.Length == 0)
	throwError();

// Get the first Loop
Loop loop = (Loop)def.Root.Nodes.GetValue(0);

// Configure ReadFilter
ReadFilter readFilter =
	SurveyDesignUtil.NewReadFilter(false,false,true,true);

// Get all forms under the loop
// (not including subloops and forms under subloops
def = SurveyDesign.GetFormsInLoop(key,projectID,loop,readFilter,SchemaSourceType.Design);

// Make iterator for the forms
IEnumerator e = def.Root.Nodes.GetEnumerator();

// Iterate through all forms and change their name
while (e.MoveNext())
	((FormBase)e.Current).Name += "_iterated";

// Update
SurveyDesign.Update(key,projectID,def);

			//***************************************************
			//
			// Get Questionnaire, change and update
			//
			//***************************************************

			// Create instance of the webservice
			SurveyDesign SurveyDesign = new SurveyDesign();

			// Get the questionnaire
			SurveySchema def = SurveyDesign.GetQuestionnaire(key,projectID,true);

			// Get the questionnaire object
			Questionnaire questionnaire = (Questionnaire)def.Root.Nodes.GetValue(0);

			// Perform some changes

			// Set new description of the project
			((ProjectInfo)questionnaire.ProjectInfo).Description = "my new description";

			// Change name of second quota if exists
			if (questionnaire.Quotas.Length >=2)
				((Quota)questionnaire.Quotas.GetValue(1)).Name = "new quota name";

			// Change the precode of the first answer of the third predefined list if exists

			// Check that the third predefined list exists
			if (questionnaire.PredefinedLists.Length >=3)
				// Check that the third predefined list has at least one answer
				if (((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.Length > 1)
					// Check that the first answer is not a reference to a predefined list
					if (((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.GetValue(0).GetType() == typeof(Answer))
						// Make the change
						((Answer)((PredefinedList)questionnaire.PredefinedLists.GetValue(2)).Answers.GetValue(0)).Precode = "newPrecode";

			// Add a new folder to Routing

			// Create Folder
			Folder folder = SurveyDesignUtil.NewFolder("new Folder");

			// Place folder after 3rd element in the routing
			ArrayList routing = new ArrayList((Array)questionnaire.Routing);
			routing.Insert(3,folder);
            questionnaire.Routing = (QuestionnaireNode[])routing.ToArray(typeof(QuestionnaireNode));

			// Update
			SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get Routing, Change, Update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Get the questionnaire
SurveySchema def = SurveyDesign.GetRouting(key,projectID,true);

// Add a new Directive to Routing

// Create Directive
Directive directive = SurveyDesignUtil.NewDirective(DirectiveDataType.Single);
ArrayList nodes = new ArrayList((Array)def.Root.Nodes);
// Insert as item #3
nodes.Insert(3,directive);
def.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get Nodes
// Get ConditionBranch
// Update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Make a new poetReadFilter
PoetReadFilter poetReadFilter =
	SurveyDesignUtil.NewPoetReadFilter(false,false,true,true,false);

// Only conditions
ArrayList nodeTypes = new ArrayList();
nodeTypes.Add(NodeType.Condition);
poetReadFilter.NodeTypes = (NodeType[])nodeTypes.ToArray(typeof(NodeType));

// Get all conditions in the project
SurveySchema def = SurveyDesign.GetNodes(key,projectID,null,poetReadFilter);

// Pick the first condition
Condition condition = (Condition)def.Root.Nodes.GetValue(0);

// Set the readfilter to include all nodetypes
poetReadFilter.IncludeAllNodeTypes = true;

// Get All Truenodes (nodes under the 'IF THEN'-part) of the condition
def = SurveyDesign.GetConditionBranch(key,projectID,condition,poetReadFilter,true);

// Add new node to place under the THEN-part
SingleForm single = SurveyDesignUtil.NewSingleForm("newSingle");

ArrayList nodes = new ArrayList((Array)def.Root.Nodes);
nodes.Add(single);
def.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get Form from name
// Get Node
// Get Forms in Loop
// Update
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Get loop by use of name (heavy task in design, light in runtime)
SurveySchema def = SurveyDesign.GetFormByName(
	key,
	projectID,
	"l1",
	SurveyDesignUtil.NewReadFilterSimple(false,false,true),
	SchemaSourceType.Design);

// Point to the loop
Loop loop = (Loop)def.Root.Nodes.GetValue(0);

// If a node is retrieved in lightweight-version it can be used to get its heavyweight-version
PoetReadFilter poetReadFilter =
	SurveyDesignUtil.NewPoetReadFilter(true,false,true,true,true);
poetReadFilter.IncludeAllForms = true;
poetReadFilter.IncludeAllNodeTypes = true;
poetReadFilter.IncludeAllLanguages = true;
def = SurveyDesign.GetNode(key,projectID,loop,poetReadFilter);

// Point to the same node, but now including languages
loop = (Loop)def.Root.Nodes.GetValue(0);

// Create new readfilter
ReadFilter readFilter =
	SurveyDesignUtil.NewReadFilter(false,false,true,true);

// Get the forms under the loop
def = SurveyDesign.GetFormsInLoop(key,projectID,loop,readFilter,SchemaSourceType.Design);

// Change the name of the first hit
FormBase form = (FormBase)def.Root.Nodes.GetValue(0);

// Add to the existing name of the form
form.Name += "_new";

// Update
SurveyDesign.Update(key,projectID,def);

//***************************************************
//
// Get PredefinedLists from project #1
// Copy into project #2
//
//***************************************************

// Create instance of the webservice
SurveyDesign SurveyDesign = new SurveyDesign();

// Make a readfilter that is complete and not projectspecific
ReadFilterSimple readFilterSimple =
	SurveyDesignUtil.NewReadFilterSimple(true,false,false);

// Get all predefined lists from sourceproject
SurveySchema defSource = SurveyDesign.GetPredefinedLists(key,projectIDSource,readFilterSimple);

// We want the destination to be projectspecific
readFilterSimple.ProjectSpecific = true;

// Get all predefine lists from destinationproject
SurveySchema defDestination = SurveyDesign.GetPredefinedLists(key,projectIDDestination,readFilterSimple);

// Transfer predefined lists
ArrayList nodes = new ArrayList((Array)defDestination.Root.Nodes);
foreach (Node node in defSource.Root.Nodes)
	nodes.Add(node);

defDestination.Root.Nodes = (Node[])nodes.ToArray(typeof(Node));

// Update destination
SurveyDesign.Update(key,projectIDDestination,defDestination);

//***************************************************
//
// FullDeployment
//
//***************************************************

// Example of how to automatically deploy a project based
// on a survey XML of an old format without WI-deployment
// information. (Note that in XMLs from ConfirmIt8.1 WI-deployment
// information is already part of the XML and the following scheme
// is only necessary if WI-deployment information is to be changed.

// Make a survey import from a file.
SurveyDesign SurveyDesign = new SurveyDesign();
XmlDocument xml = new XmlDocument();
xml.Load(filename);
string newProjectId = SurveyDesign.ImportSurvey(key,xml.InnerXml);

// Retrieve the project information
SurveySchema schema = SurveyDesign.GetProjectInfo(key,newProjectId);
ProjectInfo pi = (ProjectInfo)schema.Root.Nodes.GetValue(0);

// Make the first of the legal languages the default language
// Note that setting the default language is necessary to be able to
// use URLs to the survey without language specified.  Setting the
// default language also prevents confirmit from using default WI-properties
// if the survey is compiled through the ConfirmIt userinterface later.
pi.DefaultLanguage = pi.Languages[0];

// Setting a few standard properties
pi.ProgressBar = true;
pi.AllowModify = false;
pi.AllowModifyComplete = false;

// Putting some values into the help and endlink fields
ArrayList urls = new ArrayList();
ArrayList texts = new ArrayList();
foreach (int language in pi.Languages)
{
	LanguageString text = new LanguageString();
	text.Language = language;
	text.Value = "Please click here...";
	texts.Add(text);

	LanguageString url = new LanguageString();
	url.Language = language;
	url.Value = "http://www.yahoo.com";
	urls.Add(url);
}
pi.EndLinkTexts = (LanguageString[])texts.ToArray(typeof(LanguageString));
pi.HelpLinkTexts = pi.EndLinkTexts;
pi.EndLinkUrls = (LanguageString[])urls.ToArray(typeof(LanguageString));
pi.HelpLinkUrls = pi.EndLinkUrls;

// Update projectInfo
SurveyDesign.Update(key,newProjectId,schema);

// Generate database and generate Web Interview
// Note that a alias for SurveyDeployer namespace was used to prevent ambigous
// names.  Normally this would have been prevented by splitting the deployer
// part into a separate class
dep.SurveyDeployer deployer = new dep.SurveyDeployer();
deployer.DeployProject(key,newProjectId,dep.DatabaseType.Production);