|
1 | | -/** |
2 | | - * @file |
3 | | - * Example 009: Assign form to form group |
4 | | - * @author DocuSign |
5 | | - */ |
6 | | - |
7 | | -const docusignRooms = require('docusign-rooms'); |
8 | | - |
9 | | -/** |
10 | | - * Get form groups |
11 | | - * @param {object} args |
12 | | - */ |
13 | | -const getFormGroups = async (args) => { |
14 | | - // Create an API with headers |
15 | | - let dsApiClient = new docusignRooms.ApiClient(); |
16 | | - dsApiClient.setBasePath(args.basePath); |
17 | | - dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
18 | | - |
19 | | - //ds-snippet-start:Rooms9Step4 |
20 | | - const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient); |
21 | | - const response = await formsGroupsApi.getFormGroups(args.accountId); |
22 | | - //ds-snippet-end |
23 | | - |
24 | | - return response; |
25 | | -}; |
26 | | - |
27 | | -/** |
28 | | - * Get form libraries |
29 | | - * @param {object} args |
30 | | - */ |
31 | | -const getForms = async (args) => { |
32 | | - // Create an API with headers |
33 | | - let dsApiClient = new docusignRooms.ApiClient(); |
34 | | - dsApiClient.setBasePath(args.basePath); |
35 | | - dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
36 | | - |
37 | | - // Get first form library id |
38 | | - //ds-snippet-start:Rooms9Step3 |
39 | | - const formLibrariesApi = new docusignRooms.FormLibrariesApi(dsApiClient); |
40 | | - const formLibraries = await formLibrariesApi.getFormLibraries(args.accountId); |
41 | | - const firstFormLibraryId = |
42 | | - formLibraries.formsLibrarySummaries[0].formsLibraryId; |
43 | | - //ds-snippet-end |
44 | | - |
45 | | - // Get offices via OfficesApi |
46 | | - const { forms } = await formLibrariesApi.getFormLibraryForms( |
47 | | - args.accountId, |
48 | | - firstFormLibraryId |
49 | | - ); |
50 | | - |
51 | | - return forms; |
52 | | -}; |
53 | | - |
54 | | -/** |
55 | | - * Assign form to form group |
56 | | - * @param {object} args |
57 | | - */ |
58 | | -const assignFormToFormGroup = async (args) => { |
59 | | - //ds-snippet-start:Rooms9Step2 |
60 | | - let dsApiClient = new docusignRooms.ApiClient(); |
61 | | - dsApiClient.setBasePath(args.basePath); |
62 | | - dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
63 | | - //ds-snippet-end |
64 | | - |
65 | | - //ds-snippet-start:Rooms9Step6 |
66 | | - const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient); |
67 | | - //ds-snippet-end |
68 | | - //ds-snippet-start:Rooms9Step5 |
69 | | - const formGroupToAssign = |
70 | | - new docusignRooms.FormGroupFormToAssign.constructFromObject({ |
71 | | - formId: args.formId, |
72 | | - isRequired: true, |
73 | | - }); |
74 | | - //ds-snippet-end |
75 | | - // Assign form to a form group via FormGroups API |
76 | | - //ds-snippet-start:Rooms9Step6 |
77 | | - const results = await formsGroupsApi.assignFormGroupForm( |
78 | | - args.accountId, |
79 | | - args.formGroupId, |
80 | | - { |
81 | | - body: formGroupToAssign, |
82 | | - } |
83 | | - ); |
84 | | - //ds-snippet-end |
85 | | - |
86 | | - console.log( |
87 | | - `Form ${args.formId} has been assigned to Form Group ID ${args.formGroupId}` |
88 | | - ); |
89 | | - return results; |
90 | | -}; |
91 | | - |
92 | | -/** |
93 | | - * Form page for this application |
94 | | - */ |
95 | | -const getFormsAndFormGroups = async (args) => { |
96 | | - let formGroups, forms; |
97 | | - |
98 | | - formGroups = await getFormGroups(args); |
99 | | - forms = await getForms(args); |
100 | | - |
101 | | - return { formGroups, forms }; |
102 | | -}; |
103 | | - |
104 | | -module.exports = { assignFormToFormGroup, getFormsAndFormGroups }; |
| 1 | +/** |
| 2 | + * @file |
| 3 | + * Example 009: Assign form to form group |
| 4 | + * @author DocuSign |
| 5 | + */ |
| 6 | + |
| 7 | +const docusignRooms = require('docusign-rooms'); |
| 8 | + |
| 9 | +/** |
| 10 | + * Get form groups |
| 11 | + * @param {object} args |
| 12 | + */ |
| 13 | +const getFormGroups = async (args) => { |
| 14 | + // Create an API with headers |
| 15 | + let dsApiClient = new docusignRooms.ApiClient(); |
| 16 | + dsApiClient.setBasePath(args.basePath); |
| 17 | + dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
| 18 | + |
| 19 | + //ds-snippet-start:Rooms9Step4 |
| 20 | + const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient); |
| 21 | + const response = await formsGroupsApi.getFormGroups(args.accountId); |
| 22 | + //ds-snippet-end |
| 23 | + |
| 24 | + return response; |
| 25 | +}; |
| 26 | + |
| 27 | +/** |
| 28 | + * Get form libraries |
| 29 | + * @param {object} args |
| 30 | + */ |
| 31 | +const getForms = async (args) => { |
| 32 | + // Create an API with headers |
| 33 | + let dsApiClient = new docusignRooms.ApiClient(); |
| 34 | + dsApiClient.setBasePath(args.basePath); |
| 35 | + dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
| 36 | + |
| 37 | + // Get first form library id |
| 38 | + //ds-snippet-start:Rooms9Step3 |
| 39 | + const formLibrariesApi = new docusignRooms.FormLibrariesApi(dsApiClient); |
| 40 | + const formLibraries = await formLibrariesApi.getFormLibraries(args.accountId); |
| 41 | + const firstFormLibraryId = formLibraries.formsLibrarySummaries.find(lib => lib.formCount > 0).formsLibraryId; |
| 42 | + //ds-snippet-end |
| 43 | + |
| 44 | + // Get offices via OfficesApi |
| 45 | + const { forms } = await formLibrariesApi.getFormLibraryForms( |
| 46 | + args.accountId, |
| 47 | + firstFormLibraryId |
| 48 | + ); |
| 49 | + |
| 50 | + return forms; |
| 51 | +}; |
| 52 | + |
| 53 | +/** |
| 54 | + * Assign form to form group |
| 55 | + * @param {object} args |
| 56 | + */ |
| 57 | +const assignFormToFormGroup = async (args) => { |
| 58 | + //ds-snippet-start:Rooms9Step2 |
| 59 | + let dsApiClient = new docusignRooms.ApiClient(); |
| 60 | + dsApiClient.setBasePath(args.basePath); |
| 61 | + dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken); |
| 62 | + //ds-snippet-end |
| 63 | + |
| 64 | + //ds-snippet-start:Rooms9Step6 |
| 65 | + const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient); |
| 66 | + //ds-snippet-end |
| 67 | + //ds-snippet-start:Rooms9Step5 |
| 68 | + const formGroupToAssign = |
| 69 | + new docusignRooms.FormGroupFormToAssign.constructFromObject({ |
| 70 | + formId: args.formId, |
| 71 | + isRequired: true, |
| 72 | + }); |
| 73 | + //ds-snippet-end |
| 74 | + // Assign form to a form group via FormGroups API |
| 75 | + //ds-snippet-start:Rooms9Step6 |
| 76 | + const results = await formsGroupsApi.assignFormGroupForm( |
| 77 | + args.accountId, |
| 78 | + args.formGroupId, |
| 79 | + { |
| 80 | + body: formGroupToAssign, |
| 81 | + } |
| 82 | + ); |
| 83 | + //ds-snippet-end |
| 84 | + |
| 85 | + console.log( |
| 86 | + `Form ${args.formId} has been assigned to Form Group ID ${args.formGroupId}` |
| 87 | + ); |
| 88 | + return results; |
| 89 | +}; |
| 90 | + |
| 91 | +/** |
| 92 | + * Form page for this application |
| 93 | + */ |
| 94 | +const getFormsAndFormGroups = async (args) => { |
| 95 | + let formGroups, forms; |
| 96 | + |
| 97 | + formGroups = await getFormGroups(args); |
| 98 | + forms = await getForms(args); |
| 99 | + |
| 100 | + return { formGroups, forms }; |
| 101 | +}; |
| 102 | + |
| 103 | +module.exports = { assignFormToFormGroup, getFormsAndFormGroups }; |
0 commit comments