Unable to get Variable info in Server Side script in Service Portal

AbdulAzeez
Mega Guru

Hello Experts,

I am using Macro variable in that i am using widget:

Here is my code:

HTML:

<div class="input-group ">

<input type="text" name="name" ng-model="c.data.inputValue" />

<button type="button" class="btn btn-danger btn-block" ng-click="c.setFieldValue()">Value</button>  

</div>

Client Controller:

function($scope) {

                                                  var c = this;

                                              c.setFieldValue = function() {

                                              c.server.update().then(function(response) {

                                                                      c.data = {};

                                                                      var g_form = $scope.page.g_form;

                                                                      var values = [];

                                                                      values = g_form.getValue('a2');

                                                                    var disp = [];

                                                                      disp = g_form.getDisplayValue('a2');

                                if(!values){

                                                                                              g_form.setValue('a2', $scope.data.sysID, $scope.data.text);

                                  }else{

                                                                                              g_form.setValue('a2', $scope.data.sysID+','+values, $scope.data.text+','+disp);            

                                                                      }

                                              });

Server Side:

(function() {

                                              if(!input)

                                              return;

                      var bTab = new GlideRecord('u_backend_table');

                      bTab.initialize();

                      bTab.u_text = input.inputValue;

                bTab.u_text1 = // I want to use Variable value

                  data.sysID = bTab.insert();

                      data.text = input.inputValue;

                   

})();

I unable to get the Variable value at above highlighted region.

FYI: i also tried with

$sp.getValue('variable_name');

$sp.getDisplayValue('variable_name');

Nothing worked

b-rad nathanfirth

1 ACCEPTED SOLUTION

Srikanth Gajjel
Kilo Guru

Hi Azeez,



Try below code.



Client Controller:



function($scope) {


var c = this;


c.setFieldValue = function() {


c.data.var1 = g_form.getDisplayValue('variable_name');


c.server.update().then(function(response) {


c.data = {};


var g_form = $scope.page.g_form;


var values = [];


values = g_form.getValue('a2');


var disp = [];


disp = g_form.getDisplayValue('a2');


if(!values){


g_form.setValue('a2', $scope.data.sysID, $scope.data.text);


}else{


g_form.setValue('a2', $scope.data.sysID+','+values, $scope.data.text+','+disp);    


}


});


}


}



Server Side:



(function() {


if(!input)


return;


var bTab = new GlideRecord('u_backend_table');


bTab.initialize();


bTab.u_text = input.inputValue;


bTab.u_text1 = input.var1;// I want to use Variable value


data.sysID = bTab.insert();


data.text = input.inputValue;    


})();




Thanks,


Srikanth


View solution in original post

6 REPLIES 6

ajaylimaye
Tera Contributor

Hi Abdul,




You can give input tag to receive your input and save that data using ng-model tag like this ng-model='c.data.var_name'. then use input.var_name in server script. This should help you.


ajaylimaye
Tera Contributor

Hi Abdul,



You Could also go through the below link for more information.



Widget developer guide


Thank you Ajay let me go thorough this and will let you know if i have any issues


ajaylimaye
Tera Contributor

Hi Abdul,



Sure. Let me know if that helps you.