enable to update the catalog item field using Server script

String
Kilo Sage

Hi Team ,

am using server script to update the multi row variable set field by using below syntax 

g_form.setValue('amount', '200');Screenshot 2023-03-08 at 5.23.53 PM.png

 

 

Screenshot 2023-03-08 at 5.29.13 PM.png

 

but enable to update ,

Please guid me 

1 ACCEPTED SOLUTION

@String ,

 

Already provided the solution HERE 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

7 REPLIES 7

Prince Arora
Tera Sage
Tera Sage

@String ,

 

You need to do something like mentioned below:
This is a sample script not exact scenario please modify your code according to mention script below:

Client SIde:

 

var inputs = {
"shipid" : $scope.page.g_form.getValue(shipid');,
"billto" : $scope.page.g_form.getValue(billto');
}
c.server.get(inputs).then(function(resp){
var resp = JSON.parse(resp);
$scope.page.g_form.setValue('amount',resp.amount);
$scope.page.g_form.setValue('quantity',resp.quantity);
})

 

 

Server Side:

 

if(input){
var billto = input.billto;
var shipid = input.shipid;

//make API call by passing the variables

//parse the data and return the output as json as

var result = {"id":"xxx" , "amount":"123","quantity" : "12"};

return JSON.stringify(result);
}

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact!

@Prince Arora 

just to understand the flow I have hard coded the result to 200  and trying to update the form ,but not working 

String_0-1678282113893.png

 

Please guide 

 

@String ,

 

Please replace your previous code and modify according to my recent reply and write the c.server.get code in the button $scope.clickmethod

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

@Prince Arora 

 

client controller :

api.controller = function($scope) {
    /* widget controller */
    var c = this;
    // $scope.clickMethod = function() {
 
    $scope.clickMethod = function() {
 
        c.data.shipto = $scope.page.g_form.getDisplayValue('shipto');
        c.data.billto = $scope.page.g_form.getDisplayValue('billto');
        alert("ship" + $scope.page.g_form.getDisplayValue('shipto'));
 
        var mrvs = $scope.page.g_form.getDisplayValue("IO:6390228f1b306d1009952f02604bcb2b"); //We can access the MRVS values via getValue, using the "IO:" prefix, followed by the MRVS sys_id
        var objList = JSON.parse(mrvs);
 
        var objMRVS = JSON.parse(mrvs);
        c.data.mrvs = objMRVS;
        c.server.update();
 
c.server.get(inputs).then(function(resp) {
        alert("end"+resp);
        var resp1 = resp;
        $scope.page.g_form.setValue('amount', resp1);
        //$scope.page.g_form.setValue('quantity',resp1.quantity);
    });
    };
};
 
server script :
 
(function() {
    /* populate the 'data' object */
    /* e.g., data.table = $sp.getValue('table'); */
    if (input && input.shipto && input.billto) {
 
     var vUtil = new global.GetPriceUtilities(); //script include 
     vUtil.checkPrice(input.shipto, input.billto, input.mrvs);
       var result='200';
//return JSON.stringify(result);
return result;
}
})();
 
is am doing in rit way ?