Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

c.server.get not working in service portals

kamade rohini
Tera Contributor

I have a requirement where user should get informational message if he is trying to attach a file of more than 3MB on a portal.

 

I'm trying to get this functionality done over a widget itself.

below are my client controller and server script.

Client controller:

 function setAttachments(attachments, action) {
alert('action inside: '+action);
 
            c.data.action = 'getGUID';
            c.data.attID = $scope.data._attachmentGUID;
            var id = c.data.attID;
            
            alert("scoped: " + $scope.data._attachmentGUID);
            alert('c.data.attID: ' + c.data.attID);
           alert('size1: ' + $scope.data.size);
var inputs={
action: 'getGUID',
            attID: id
}
           c.server.get(inputs).then(function(response) {
                alert('size: ' + $scope.data.size);
  c.server.update();
            });
        }
        $scope.attachments = attachments;
 
    }



Server script:
data._attachmentGUID = gs.generateGUID();
if (input && input.action == 'getGUID') {
data.final_size=0;
  gs.log("input.attID: "+input.attID,'rohini');
var att = new GlideRecord('sys_attachment');
        att.orderBy('sys_created_on');
        att.addQuery('table_sys_id',input.attID);
        att.query();
        while(att.next()) {
           data.size = att.size_bytes;
gs.log("data.size " + data.size, "rohini");
gs.log("Count1: " + att.getRowCount(), "rohini");
        }
    }



Now, I'm able to get size of attached of file on a server side in logs. but at the same I'm unable to fetch it on client side.
0 REPLIES 0