We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

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
Mega 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

Srikanth Gajjel
Mega 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


Thanks Srikanth it helped