The CreatorCon Call for Content is officially open! Get started here.

Onclick of button data should be pushed in table format.

Sweenal
Tera Contributor

Hi All,

Please help me with this requirement:

1. Create Catalog item "Access Request" and Create variables as shown in the SS i.e. Category,Short Description, Incorrect Serial Number,Correct Serial Number.

2. Create Add button.

3. When clicked on Add button, data should be pushed in table in below format. (as seen in SS)

Hint - To create add button, use variable type - Custom. On that you need to create widget and add it in the variable's widget.

This should be done in service portal only. 

After inserting the data when clicked on add button the data should be pushed in table.

Thanks

Sweenal Umredkar

1 ACCEPTED SOLUTION

Ravi9
ServiceNow Employee
ServiceNow Employee

Here is a SAMPLE , you will have to take it from there and make it work accordingly though ! I will point out that you need to have portal experience one more time !

Widget HTML

<button type="button" class="btn btn-success" ng-click="c.add()">Add</button>
<table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Name</th>
      <th scope="col">Age</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="item in c.storage track by $index">
      <th scope="row">{{$index}}</th>
      <td>{{item.name}}</td>
      <td>{{item.age}}</td>
    </tr>
  </tbody>
</table>

Widget Controller

api.controller = function ($scope) {
  /* widget controller */
  var c = this;
  c.storage = [];
  c.add = function () {
    // store only if button clicked
    c.storage.push({
      name: c.name,
      age: c.age,
    });
  };
  // look for changes !
  $scope.$watch(
    function () {
      return $scope.page.g_form.getValue("age");
    },
    function (age) {
      c.age = age;
      c.name = $scope.page.g_form.getValue("name");
    }
  );
};

How it looks

find_real_file.png

View solution in original post

24 REPLIES 24

Hi,

why widget when OOB MRVS can be used?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

As you can see in that screenshot I have two fields incorrect serial number and correct number.

So If I Put the values 10 and 11 in these two fields and when i click on add button it should get display in the table form with values inserted.

Please refer the attachment for clear understanding.

Thanks

Sweenal

Hi,

so are you saying when you click Add button then the entered values of 10 and 11 should be auto-populated in the MRVS as 1 row

Why to have same information stored in MRVS?

You can just keep MRVS and user can add 1 row or multiple rows

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

I dont want to use MRVS I have to create add button and table so when user fills the information onclick of button this filled information should be pushed in the table.

I don't want to use MRVS but by editing it in the widget.

Please can you help me with this.

Thanks

Sweenal

I had a similar requirement in the Past as it requires lot of customisation we preferred to go for OOB - MRV's functionality