Get Catalog variable value from a widget

madhusagar
Tera Contributor

Hello All, 

I have a order guide which has a Lookup select box variable "Model" referenced to Vendor Items table(pc_vendor_cat_item). In this variable I am display the product model names as choices for the user. My requirement to display the price of the user selected model in "Order Guide Details" section from Sc order widget at the time of form submission. 

madhusagar_0-1762953593396.png

madhusagar_1-1762953622145.png

In OOB it displays the catalog item price and so I cloned the widget and added the below server-side logic trying to hardcode the model sysid in server script and get the value and display in price using html. 

 

Server script: 

data.modelPrice=''; 

var gr = new GlideRecord('pc_vendor_cat_item'); 

gr.addQuery('sys_id','b0f089da37313000158bbfc8bcbe5d0b'); 

gr.query(); 

if(gr.next()){ 

data.modelPrice=gr.getDisplayValue(('price')); 

gs.log("Portal Value: " + data.modelPrice); 

} 

HTML : 

In Html I changed the OOB script for displaying price as below 

<td class="wrapper-sm v-middle text-a-c hidden-xs hidden-sm"> 

<span><strong>{{::data.modelPrice}}</strong></span> 

</td> 

 

The above script works for hardcoded model sysIds but how should I dynamically get the user selected model and then pass to the server script of the widget so it will display the price of model exactly. 

 

Could anyone please help me to retrieve the value of variable and pass it in the dynamically to server side and print the price. Thanks in advance. 

3 REPLIES 3

Devi
Tera Contributor

var varaiblvalue = $scope.data.sc_cat_item.variables['variable_name'].value;

// Call server script and pass the value
$scope.server.update({
varaiblvalue: varaiblvalue
}).then(function(response) {
console.log('Server response:', response);
});

server script

 

(function() {
// Access the value sent from client
var myVarValue = input.varaiblvalue;
gs.info('Received variable value: ' + myVarValue);


// Do something with it, e.g., query or update
data.result = 'Server got: ' + myVarValue;

var gr = new GlideRecord('pc_vendor_cat_item');

gr.addQuery('sys_id',myVarValue);

gr.query();

if(gr.next()){

data.modelPrice=gr.getDisplayValue(('price'));

gs.log("Portal Value: " + data.modelPrice);

}
})();

Hi Devi,
The above question was asked by team mate and so I am also working on it . Can you pls explain this line:

var varaiblvalue = $scope.data.sc_cat_item.variables['variable_name'].value;

My variable name is user_model then should it be like this
var varaiblvalue = $scope.data.sc_cat_item.variables['user_model'].value;

I tried like above and used the rest of code for cs and server script. After that Its not loading the catalog widget itself. It's blank when page loads.

Can you pls help me to achieve this one. Thanks in advance.

once try this line in server script and check whether you are getting the value for modal

 

data.user_model = $sp.getValue('user_model');

gs.info("Model name in widget" + data.user_model);