/** * BranchCheck export helper v0.1.0 * @OnlyCurrentDoc * Paste into a NEW script file bound to your Google Form. * Reads titles, choice labels and section navigation. Never reads responses, * modifies the form, or sends requests to external services. */ function exportBranchCheck() { var form = FormApp.getActiveForm(); if (!form) throw new Error('Open your form editor, then its three-dot menu > Script editor. This helper must be bound to a form.'); var snapshot = branchCheckSnapshot_(form); var json = JSON.stringify(snapshot, null, 2); var escape = function(s) { return s.replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); }; var html = '
This contains your questions and routes, not respondent answers. Download it, then choose it in BranchCheck.
'+ ''+ 'If download is blocked, select and copy the text below into BranchCheck’s “Paste snapshot” box.
'+ ''+ 'You can remove the helper after exporting. Re-export whenever the form changes.
'; FormApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html).setWidth(620).setHeight(540),'BranchCheck export'); } function branchCheckSnapshot_(form) { var sections = [{id:'start',title:'1. '+(form.getTitle()||'First section'),next:{type:'SUBMIT'},questions:[]}]; var current = sections[0], warnings=[]; function navigation(type, target) { if (type == null) return null; var name=String(type); if(['CONTINUE','SUBMIT','RESTART','GO_TO_PAGE'].indexOf(name)===-1) throw new Error('Unsupported navigation type: '+name); return name==='GO_TO_PAGE' ? {type:name,target:target?String(target.getId()):'missing-target'} : {type:name}; } form.getItems().forEach(function(item) { var type=String(item.getType()); if(type==='PAGE_BREAK') { var page=item.asPageBreakItem(); // The NEXT page-break item stores the PREVIOUS section's exit rule. current.next=navigation(page.getPageNavigationType(),page.getGoToPage())||{type:'CONTINUE'}; current={id:String(page.getId()),title:(sections.length+1)+'. '+(page.getTitle()||'Untitled section'),next:{type:'SUBMIT'},questions:[]}; sections.push(current); } else if(type==='MULTIPLE_CHOICE') { var q=item.asMultipleChoiceItem(); current.questions.push({title:q.getTitle(),required:q.isRequired(),choices:q.getChoices().map(function(c){return {label:c.getValue(),nav:navigation(c.getPageNavigationType(),c.getGotoPage())};})}); if(q.hasOtherOption()) warnings.push('Section '+current.title+': “Other” option in “'+q.getTitle()+'” is not modeled. Confirm this path in Google Forms.'); } else if(type==='LIST') { warnings.push('Section '+current.title+': dropdown question “'+item.getTitle()+'” may contain routing that this helper cannot reliably read. This report is incomplete; inspect dropdown routes manually.'); } }); return {schema:'branchcheck.v1',title:form.getTitle(),source:'Google Forms · bound export helper v0.1.0',exportedAt:new Date().toISOString(),warnings:warnings,sections:sections}; }