File tree Expand file tree Collapse file tree
Modern Development/Service Portal Widgets/Fill survey or item from url Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //Server script:
2+ ( function ( ) {
3+ //get the data parameter with base64encoded json with field names for keys and matching values
4+ data . encodedData = $sp . getParameter ( "data" ) ;
5+ try {
6+ //turn the data back into a js object
7+ data . decodedData = JSON . parse ( GlideStringUtil . base64Decode ( data . encodedData ) ) ;
8+ } catch ( e ) {
9+ //bad json; do nothing
10+ return ;
11+ }
12+ } ) ( ) ;
13+
14+
15+ //Client controller:
16+ api . controller = function ( $scope , $rootScope ) {
17+
18+ var c = this ,
19+ g_form = $scope . page . g_form ,
20+ answerMap = c . data . decodedData ;
21+ // return if the answermap is not a valid object
22+ if ( ! answerMap instanceof Object )
23+ return ;
24+ // if we have g_form set values from the data parameter to form
25+ if ( g_form ) {
26+ fillAnswers ( ) ;
27+ }
28+ //loops through the object with field name keys and corresponding values and sets values
29+ function fillAnswers ( ) {
30+ for ( key in answerMap ) {
31+ if ( ! answerMap . hasOwnProperty ( key ) && ! g_form . hasField ( key ) )
32+ continue ;
33+ g_form . setValue ( key , answerMap [ key ] ) ;
34+ }
35+ }
36+ //get gform from the spmodel
37+ $rootScope . $on ( 'spModel.gForm.initialized' , function ( e , gFormInstance ) {
38+ g_form = gFormInstance ;
39+ fillAnswers ( ) ;
40+ } ) ;
41+ } ;
You can’t perform that action at this time.
0 commit comments