View this page in the latest version of Appian. Use the Write Records Smart Service Function on an Interface Share Share via LinkedIn Reddit Email Copy Link Print On This Page Tip: Interface patterns give you an opportunity to explore different interface designs. Be sure to check out How to Adapt a Pattern for Your Application. Goal Allow the user to publish several rows of data to a database table with the a!writeRecords() smart service function. Note: This expression uses direct references to the Employee record type, created in the Records Tutorial. If you've completed that tutorial in your environment, you can change the existing record-type references in this pattern to point to your Employee record type instead. Follow this recipe to create example data and supporting objects to use with other interface recipes (including those that use record types) and tutorials like the Record Type Tutorial (Database). This recipe shows you: How to use the a!writeRecords() smart service function to create record data directly from an interface. How to use the disabled parameter of an interface component based on user interactions. Recipe prerequisites To complete this recipe, you need: Appian Tutorial application. Complete the Application Building Tutorial to store the interface used in this recipe. AT Employee record type: Complete the Create the AT Employee record type section of the Record Type Tutorial, including the Generate a database table subsection. The generated database table is the target for the data written in this recipe. Create an interface to write data To create an interface to write data using the a!WriteRecords() function: In the Build view of your application, click NEW > Interface. Configure the following properties: Property Description Name Enter: <prefix>_employeeData Description Enter: Interface for loading employee data Folder Select the appropriate folder in your application or, if it doesn't exist, create it by clicking the Create New Rule Folder link. Click CREATE. In your new interface, click Expression mode . In the INTERFACE DEFINITION pane, paste the expression below. Since record type references are specific to each environment, you need to update the expression to work with your application: Line 28: In the cast() function, replace recordType!Employee with your record type. Line 38: In the a!queryRecordType() function, replace the recordType value of recordType!Employee with your record type. Line 40 - 45: In the a!queryRecordType() function, replace the fields values with record field references from your record type. Line 52: In the a!sortInfo() function, replace the field value of recordType!Employee.field.id with a reference to your record type's id field. Click SAVE. To write the data, click PUBLISH DATA. After data has been written to your database, the button text changes to DATA ALREADY PUBLISHED. The button will stay disabled as long as there is employee data present in the database table. Tip: Check out the Record Type Tutorial (Database) to configure the rest of this record type! Expression 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 a!localVariables( /* The data to load into the record data source. */ local!dataToLoad: a!forEach( { a!map( firstName: "John" , lastName: "Smith" , departmentId: 1 , title: "Director" , phoneNumber: "555-123-4567" , startDate: today()-360 ), a!map( firstName: "Michael" , lastName: "Johnson" , departmentId: 2 , title: "Analyst" , phoneNumber: "555-987-6543" , startDate: today()-360 ), a!map( firstName: "Mary", lastName: "Reed" , departmentId: 1 , title: "Software Engineer" , phoneNumber: "555-456-0123" , startDate: today()-240 ), a!map( firstName: "Angela" , lastName: "Cooper" , departmentId: 3 , title: "Manager" , phoneNumber: "555-123-4567" , startDate: today()-240 ), a!map( firstName: "Elizabeth" , lastName: "Ward" , departmentId: 3 , title: "Sales Associate" , phoneNumber: "555-987-6543" , startDate: today()-240 ), a!map( firstName: "Daniel", lastName: "Lewis" , departmentId: 4 , title: "Manager" , phoneNumber: "555-876-5432" , startDate: today()-180 ), a!map( firstName: "Paul" , lastName: "Martin" , departmentId: 2 , title: "Analyst" , phoneNumber: "555-609-3691" , startDate: today()-150 ), a!map( firstName: "Jessica" , lastName: "Peterson" , departmentId: 2 , title: "Analyst" , phoneNumber: "555-987-6543" , startDate: today()-150 ), a!map( firstName: "Mark" , lastName: "Hall" , departmentId: 5 , title: "Director" , phoneNumber: "555-012-3456" , startDate: today()-150 ), a!map( firstName: "Rebecca" , lastName: "Wood" , departmentId: 1 , title: "Manager" , phoneNumber: "555-210-3456" , startDate: today()-150 ), a!map( firstName: "Pamela" , lastName: "Sanders" , departmentId: 1 , title: "Software Engineer" , phoneNumber: "555-123-4567" , startDate:today()-120 ), a!map( firstName: "Christopher" , lastName: "Morris" , departmentId: 5 , title: "Consultant" , phoneNumber: "555-456-7890" , startDate: today()-120 ), a!map( firstName: "Kevin" , lastName: "Stewart" , departmentId: 5 , title: "Manager" , phoneNumber: "555-345-6789" , startDate: today()-120 ), a!map( firstName: "Stephen" , lastName: "Edwards" , departmentId: 3 , title: "Sales Associate" , phoneNumber: "555-765-4321" , startDate: today()-120 ), a!map( firstName: "Janet", lastName:"Coleman" , departmentId: 2 , title: "Director" , phoneNumber: "555-654-3210" , startDate: today()-90 ), a!map( firstName: "Scott" , lastName: "Bailey" , departmentId: 1 , title: "Software Engineer" , phoneNumber: "555-678-1235" , startDate: today()-30 ), a!map( firstName: "Andrew" , lastName: "Nelson" , departmentId: 5 , title: "Consultant" , phoneNumber: "555-789-4560" , startDate: today()-30 ), a!map( firstName: "Michelle" , lastName: "Foster" , departmentId: 4 , title: "Director" , phoneNumber: "555-345-6789" , startDate: today()-30 ), a!map( firstName: "Laura" , lastName:"Bryant" , departmentId: 3 , title: "Sales Associate" , phoneNumber: "555-987-6543" , startDate: today()-14 ), a!map( firstName: "William" , lastName: "Ross" , departmentId: 1 , title: "Software Engineer" , phoneNumber: "555-123-4567" , startDate: today()-10 ), a!map( firstName: "Arya" , lastName:"Colson" , departmentId: 3 , title: "Sales Associate" , phoneNumber: "555-927-3343" , startDate: today()-5 ) }, cast( recordType!Employee, fv!item ) ), /* This value gets updated when the user clicks on the PUBLISH DATA button in order to disable it so the user can't click it multiple times. */ local!submitted: false, /* The refresh variable watches local!submitted and reruns the query when it changes. */ local!records: a!refreshVariable( value: a!queryRecordType( recordType: recordType!Employee, fields: { recordType!Employee.fields.firstName, recordType!Employee.fields.lastName, recordType!Employee.fields.departmentId, recordType!Employee.fields.title, recordType!Employee.fields.phoneNumber, recordType!Employee.fields.startDate }, pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 1000, sort: a!sortInfo( field: recordType!Employee.fields.id, ascending: true ) ), fetchTotalCount: true ), refreshOnVarChange: local!submitted ), local!hasData: not(local!records.totalCount=0), a!sectionLayout( contents: { a!buttonLayout( secondaryButtons:{ a!buttonWidget( label: if(local!hasData, "Data Already Published", "Publish Data"), saveInto: { a!writeRecords( records: local!dataToLoad, onSuccess: a!save(local!submitted, true) ) }, submit: true, style: "SOLID", disabled: or(local!hasData, local!submitted) ) } ) } ) ) Feedback Was this page helpful? SHARE FEEDBACK Loading...