Service portal: clicking on button should make record active true

raja_5
Tera Expert

Hi Experts,

I have simple list widget on left hand side and custom widget on right handside, on the selection of records which are inactive i should see a button reactivate and when clicking on it ,the input/selected record should be active true

 

HTML :

<button class="btn btn-primary" ng-click="c.reactivateprj()">${Reactivate}</button>

 

Client script :

c.reactivateprj = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'reactivate',
scope: $scope
});

// Call the server-side function to reactivate the project
c.server.reactivateprj();

 

Server script : function reactivateprj(input) {
var proj = new GlideRecord('table_name');
proj.addQuery('sys_id', input.sys_id);
gs.info('printvalue'+input.sys_id);
proj.query();
while (proj.next()) {
proj.active = true;
proj.update();
}

Please help

4 REPLIES 4

Tushar
Kilo Sage
Kilo Sage

Hi there,

 

can you please try below -

 

HTML

 

<button class="btn btn-primary" ng-click="c.reactivateprj()">${Reactivate}</button>

 

client script - 

c.reactivateprj = function() {
  c.modalInstance = $uibModal.open({
    templateUrl: 'reactivate',
    scope: $scope
  });

  // Pass the selected record's sys_id to the server-side function
  c.server.reactivateprj({ sys_id: c.data.selectedRecord.sys_id });
};

 

server script -

function reactivateprj(input) {
  var proj = new GlideRecord('table_name');
  proj.addQuery('sys_id', input.sys_id);
  gs.info('printvalue' + input.sys_id);
  proj.query();
  if (proj.next()) {
    proj.active = true;
    proj.update();
  }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

Hi @Tushar  ,

 

Thank you for you response,

 

tried above but no luck,

 

 

please find existing server script :

(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */
 
    if (!input) return;
 
 
    var fields = "sys_id,name,account,description";
    var pjGr = new GlideRecord("prj_desc");    
    if (pjGr.get(input.sys_id)) {
        data.record = {};
        $sp.getRecordElements(data.record, pjGr, fields);
        gs.info('print value of input.sys_id' + input.sys_id);
 
 
    }
 
function reactivateprj(input) {
gs.info('inputvalue'+input);
  var proj = new GlideRecord('prj_desc');
  proj.addQuery('sys_id', input.sys_id);
  gs.info('printvalue' + input.sys_id);
  proj.query();
  if (proj.next()) {
    proj.active = true;
    proj.update();
  }
}
 
 
 
})();
 
 
 
Client script :
 c.reactivateprj = function() {
  c.modalInstance = $uibModal.open({
    templateUrl: 'reactivate',
    scope: $scope
  });
 
  // Pass the selected record's sys_id to the server-side function
  c.server.reactivateprj({ sys_id: c.data.selectedRecord.sys_id });
  alert('check'+c.data.selectedRecord.sys_id);
};
 
no info message in logs from server script and no alert message as well
 
Please suggest

Updated one -

 

(function () {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

  if (!input) return;

  var fields = "sys_id,name,account,description";
  var pjGr = new GlideRecord("prj_desc");
  if (pjGr.get(input.sys_id)) {
    data.record = {};
    $sp.getRecordElements(data.record, pjGr, fields);
    gs.info('print value of input.sys_id' + input.sys_id);
  }
})();

// Define the reactivateprj function outside the IIFE
function reactivateprj(input) {
  gs.info('inputvalue' + input);
  var proj = new GlideRecord('prj_desc');
  proj.addQuery('sys_id', input.sys_id);
  gs.info('printvalue' + input.sys_id);
  proj.query();
  if (proj.next()) {
    proj.active = true;
    proj.update();
  }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

 

@Tushar  Still the same ,its not entering the function reactivateprj()

 

 

 

updated client script :

 var c = this;
 
  $scope.$on("$sp.list.click", function(e, obj) {
    $scope.data.sys_id = obj.record.sys_id;
    c.server.update();
  });
 
  
 
  c.reactivateprj = function() {
  c.modalInstance = $uibModal.open({
    templateUrl: 'reactivate',
    scope: $scope
  });
 
  // Pass the selected record's sys_id to the server-side function
  c.server.reactivateprj({ sys_id: c.data.selectedRecord.sys_id });
  alert('check'+c.data.selectedRecord.sys_id);
};
};