Service Portal Input Directives

Brian Treichel
Tera Guru

Hello,

I am trying to create an input in a widget that functions the same as a List Collector (Glide List) catalog variable, but I can't tell if there is a directive out there that I can use.

I know that, for Reference Variables, there is a sn-record-picker directive, but I'm not sure if there are directives for the other types. Are there any other "Glide" types are there directives for, i.e. Lists/Duration, Date/Time, etc? I'm thinking they must be somewhere. The only place that I would think to find them would be in the Catalog Item widget, but that uses another directive <sp-cat-item item='item' /> to gather the variables, which I'm not sure I can even access.

Any ideas?

Thanks,

Brian

1 ACCEPTED SOLUTION

LaurentChicoine
Tera Guru

Hi Brian to make a Glide list field, you can use the sn-record-picker directive. Here is an example:



HTML:



<sn-record-picker field="watch_list" table="'sys_user'" display-field="'name'" value-field="'sys_id'" default-query="'active=true'" multiple="true"></sn-record-picker>



Client script (you must set the field inside your client script):



function($scope, spUtil) {


      var c = this;



      $scope.watch_list = {


              displayValue: variable_with_display_value_comma_separated, //This should not be null


              value: variable_with_value_comma_separated, //This should not be null


              name: 'watch_list'


        };


}


View solution in original post

14 REPLIES 14

Of my knowledge it is only unofficially documented (however it is used in OOTB example widgets):


Reference Fields with the snRecordPicker Directive - ServicePortal.io - Service Portal, CMS, and Cus...



As for the mutliple attribute I did not see it documented anywhere and found it by reverse engineering.



As for other directives like this, I did not see documentation for them but here is a quick list but I did not look into how to use them:


  • sn-user-profile
  • sn-avatar-popover
  • sn-avatar
  • sn-user-avatar
  • sn-group-avatar
  • sn-choice-list
  • sn-reference-picker
  • sn-select-basic
  • sn-table-reference
  • sn-field-reference
  • sn-sync-with
  • sn-image-uploader
  • sn-link-content
  • sn-link-content-youtube
  • sn-link-content-soundcloud


Also there seems to be directives for every type of fields but they don't seems to be made to be used stand alone as I was not able to properly use them without having the whole form widget loaded (sp-model).


Hi Laurent,



I was able to implement your code and i am still stuck in the issue where in i am not able to select the values from the watchlist however i am able to see the values in the drill down.



This is a bit urgent so any help would do.



Thanks,


Shahid


Hi Shahid,



I remember facing this issue. However I don't remember how to reproduce it. Could you look at your javascript console for any error.



Also maybe try to post your full widget code so I can test it.



Here is another topic which has examples of the multiple value reference field: How to get a watch list in widget in Service Portal ?


shahid1
Kilo Expert

HI Laurent,



Below is the code:-



HTML:-


<div class="filterband">


  <div class="filter-liner container">


     


      <div class="panel panel-default">


      <div class="col-sm-2">


              Select Choice


      </div>


</div>


<div class="col-sm-7">


      <sn-record-picker field="watch_list" table="'u_c_choice_definition'" display-field="'u_choice_name'" value-field="'sys_id'" default-query="'u_choice!=Retired'" search-fields="'u_choice_name'" multiple="true"></sn-record-picker>    


      </div>


  </div>


</div>




Client Script:-


$scope.watch_list = {  


              displayValue: $scope.data.u_choice_name,


              value: $scope.data.sys_id,


              name: 'watch_list'  


        };  


  $scope.$on("field.change", function(evt, parms) {            


      if (parms.field.name == 'u_choice_name'){


              $scope.data.u_choice_name = parms.newValue;


              $scope.server.update();


      }


});



Server Script:- No Server Script



I appreciate your help here.



Thanks,


Shahid


Hi,



Your $scope.data seems to be undefined which is causing error in the javascript console.



I'm not sure what you are trying to achive with the $scope.data.u_choice_name but as stated the value and display value should not me null.



Just to make it work you should try the following client script:



function($scope, spUtil) {


  $scope.watch_list = {


  displayValue: $scope.data.u_choice_name || [],


  value: $scope.data.sys_id || [],


  name: 'watch_list'


  };


  $scope.$on("field.change", function(evt, parms) {


  if (parms.field.name == 'u_choice_name'){


  $scope.data.u_choice_name = parms.newValue;


  $scope.server.update();


  }


  });


}