Need help with script to build a select box type variable on a custom Service Portal form

patricklatella
Mega Sage

Hi all,

I'm building a custom widget to present a custom form in Service Portal, and need to build a Select Box type variable...and I'm struggling with the script in the HTML field of the widget.  Here's where I'm at so far, I got this from Stackoverflow.com and am trying to manipulate for my need.  Anyone done this before?  Thanks!

<div class="select">
         <select [(ngModel)]="corporationObj" class="form-control col-lg-8" #corporation required>
             <option *ngFor="let corporation of corporations"></option>    
         </select>
         
     </div>
1 ACCEPTED SOLUTION

 <div class="form-group">
 <label for="technology">What technology is this related to?</label>
 <select id="technology" name="technology"
 ng-model="c.data.technology" class="form-control">
 <option value="">--None--</option>-->
 <option value="1">Help Desk</option>
 <option value="2">IT</option>
 <option value="3">Payroll</option>
 </select>
 </div>

View solution in original post

22 REPLIES 22

For that, you have to write your own code inside the client and server script according to your requirement.

Please refer below link for sn-record-picker

 

https://serviceportal.io/sn-record-picker/

that is so funny...that's exactly where I started!  Ha...well thanks so much...you've been extremely helpful.  Any thoughts on how to get the fields to be mandatory?

patricklatella
Mega Sage

Nathan's client controller script for the sn-record-picker looks like this on that page...I'm a little lost as to what to do with it for my needs...any suggestions?

$scope.location = {
displayValue: c.data.loc.name,
value: c.data.loc.sys_id,
name: 'location'
};
 
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'location')
c.data.setLocation = parms.newValue;
 
c.server.update().then(function(response) {
spUtil.update($scope);
})
});

patricklatella
Mega Sage

thanks again for all your help Shweta...I want to mark your answer as correct, so here was the script that actually answered my question about how to create a Select Box variable...so if you want to copy and paste this script in one more reply I'll mark your answer correct.  thanks for all the extra help too!

 

SCRIPT TO CREATE A SELECT BOX TYPE VARIABLE ON A CUSTOM FORM WIDGET.  ENTER IN THE WIDGET'S HTML FIELD.

PASSES THE VALUE FROM THE SELECT BOX TO THE WIDGET'S CLIENT SCRIPT AS "c.data.technology" (in this example)


<div class="form-group">
<label for="technology">What technology is this related to?</label>
<select id="technology" name="technology"
ng-model="c.data.technology" class="form-control">
<option value="">--None--</option>-->
<option value="1">Help Desk</option>
<option value="2">IT</option>
<option value="3">Payroll</option>
</select>
</div>