portal widget bulk update

ganilyilmaz
Tera Contributor

Hi everyone,

 

We have a custom solution that we created on Servicenow. But I'm stuck at a part.
I would like to express the situation as follows:
We have a widget where we list the information about the rhythms. In this widget, we show the line items of the recording. I have no problem listing the line items of the recording. However, I want the user to enter some values into these line items and update all of the line items with a single button. Before that, the user can access each line item. It was approving one by one. Now I want it to be approved collectively. However, I cannot match the rhythm with the values written on the line items.

 

MY HTML CODE

 

  <section class="intro" style="margin-left:15px;width:100%;">
  <div class="bg-image h-100" style="background-color: transparent;">
    <div class="mask d-flex align-items-center h-100">
      <div class="container">
        <div class="row justify-content-center">
          <div class="col-12">
            <div class="card mask-custom">
              <div class="card-body">
                <div class="table-responsive">
                  <form ng-submit="$event.preventDefault()" >
                  <table class="table table-bordered align-middle table-nowrap  mb-0" style="background-color: transparent;width:100%;">
                    <thead class="table-light">
                      <tr class="text-muted" style="background-color: transparent;">
                        <th class="kabartma"><a style="font-size:1.2rem; color:black;">Number</a></th>
                        <th class="kabartma"><a style="font-size:1.2rem; color:black;">Item Code</a></th>
                     ......
                      </tr>
                    </thead>
             <tbody>
  <tr ng-repeat="lpro in data.lprobs">
     <td><a href="">{{lpro.u_numb}}</a></td>
    <td><a style="font-size:1.4rem; color:black;">{{lpro.u_item_code}}</a></td>
 ......
     <td> 
      <select ng-model="c.data.input1" style="color:black;">
        <option ng-repeat="state in c.data.states" value="{{state.value}}">{{state.label}}</option>
      </select>
      <a style="font-size:1.4rem; color:black;"></a>
    </td>
    <td>
      <input type="text" ng-model="c.data.input2" style="color:black;">
      <a style="font-size:1.4rem; color:black;"></a>
    </td>
    <td>
      <input type="text" ng-model="c.data.input3" style="color:black;">
      <a style="font-size:1.4rem; color:black;"></a>
    </td>
    <td>
      <input type="text" ng-model="c.data.input4" style="color:black;">
      <a style="font-size:1.4rem; color:black;"></a>
    </td>
</tbody><tr>
  <button type="button" name="close" class="btn btn-success btn-question" ng-click="c.action()" style="width:120px;">Submit</button>
</tr>
                  </table>
                     </form>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>​



MY SERVER SCRİPT CODE 

 

 

 

var gr = $sp.getRecord();
var c = this;
if (gr.getTableName() == 'table_name') {
  
    var fields = $sp.getFields(gr, 'sys_created_on,u_tax_code,u_gl_account,u_wbs,u_cost_center,number,u_item_code,u_quantity,u_description,u_unit_price,u_vat_tax,u_vat_amount,u_discount,u_unit,u_amount,');

    if (gr) {
        data.Visible = true;
        if (gr.sys_mod_count > 0)
            fields.push($sp.getField(gr, 'sys_updated_on'));
        data.fields = fields;
        data.state = gr.state.toString();
        data.sys_updated_on = gr.sys_updated_on.toString();
        data.sys_id = gr.getUniqueValue();
        data.table = gr.getTableName();
        data.user = gs.getUserID();       
        data.states = []; 
        var incStates = new GlideRecord('table_name'); 
        incStates.orderByDesc('u_tax_code');
        incStates.query();
        while (incStates.next()) {
            var stateObj = {};
            stateObj.label = incStates.u_tax_code.toString();
            stateObj.value = incStates.getUniqueValue().toString();
            data.states.push(stateObj); // Çekilen veriyi diziye ekliyoruz
        }
        c.data.lprobs = [];
        var litem = new GlideRecord('table_name');
        litem.addQuery('u_req_number', data.sys_id);
        litem.query();
        var count = 0;
        while (litem.next()) {
            count = count + 1;
            var lpro = {};
            lpro.u_numb = litem.getDisplayValue('number');
            lpro.u_item_code = litem.getDisplayValue('u_item_code');
            lpro.u_quantity = litem.getDisplayValue('u_quantity');
            lpro.u_description = litem.getDisplayValue('u_description');
            lpro.u_unit_price = litem.getDisplayValue('u_unit_price');
            lpro.u_vat_tax = litem.getDisplayValue('u_vat_tax');
            lpro.u_vat_amount = litem.getDisplayValue('u_vat_amount');
            lpro.u_discount = litem.getDisplayValue('u_discount');
            lpro.u_unit = litem.getDisplayValue('u_unit');
            lpro.u_amount = litem.getDisplayValue('u_amount');
            lpro.u_gross_amount = litem.getDisplayValue('u_gross_amount');
            lpro.u_tax_code = litem.getDisplayValue('u_tax_code');
            lpro.u_gl_account = litem.getDisplayValue('u_gl_account');
            lpro.inputvalue = "input_" + litem.getDisplayValue('number');
            lpro.u_wbs = litem.getDisplayValue('u_wbs');
            lpro.u_cost_center = litem.getDisplayValue('u_cost_center');
            lpro.id = litem.getDisplayValue('sys_id');            
            c.data.lprobs.push(lpro);
            var lprobs = c.data.lprobs;
            var lsys_id = lpro.id;                     
            for (var i = 0; i < count; i++) {
                
                var record = lsys_id;
                var inputValue = record.inputValues;
                gs.addInfoMessage(records);               
                if (input.input1 || input.input2 || input.input3 || input.input4 && record ) {
                    gs.addInfoMessage(record);
                    var gr1 = new GlideRecord('table_name');
                    gr1.addQuery('sys_id', record);
                    while (gr1.next()) {
                        gr1.u_tax_code = input.input1;
                        gr1.u_cost_center = input.input2;
                        gr1.u_wbs = input.input3;
                        gr1.u_gl_account = input.input4;
                        gr1.u_controller_update = "Yes";
                        gr1.update();
                    }                  
                }                
            }
        }

    }
}

lineitem.pngPortal Lineitems.pngAfter clicking to lineitem.png

 

5 REPLIES 5

Wybren1
Tera Guru

I'm not getting the full picture, so it's hard to give a solution:

- The user should have the ability to adjust information on each line item?

- The user should have the ability to approve all of the line items at once?

So your combining the two screenshots? the yellow one and the one with the green button?
Showing the client script can also be helpfull.

In a nutshell, ng-model is client sided and keeps track of all the changes, but your not binding it to the line itself.
ng-repeat="lpro in c.data.lprobs"
ng-model="lpro.input1" etc

Then keep track of the c.data.lprobs and use that to update it to the server side. You already have the lpro.id that should be easy enough to update them with an approval.

ganilyilmaz
Tera Contributor

The user will fill in and update the input section of each record returned by the script. But while usually returns more than one record, so there will be more than one record in the table.

Each record may have different values; they will not have the same value.

Once you press the button, all records will be updated according to the data in the inputs.

In the table in the yellow section, it used to go to each record individually to update the records one by one, but now they want to update all records at once. The numbers there contain the id of the table, and in the while control, I bring the records belonging to the record to update them.

Yes, I have the id, but I could not get the id of the updated row and perform the update.

So basically a "save all" option? You change one or multiple records in the list and once done you "save" it and want to update it?

After filling in the inputs as shown in the 3rd picture, I want each record to be updated within itself when I press the submit button.