Autopopulate multi-row variable set through Widget

Swathi P
Tera Guru

Hi All,

I am trying to autopopulate multi -row variable set through widget. I have added the below script in client controller. I am unable to set the variables in variable sets. Please help. i am doing anything wrong here.

var my_varset_three_way = $scope.page.g_form.getField("invoice_line_items");
      
        for (var sKey in details) {
            if (sKey == "invoice_line_items") {
                alert(sKey);
                alert($scope.page.g_form.getValue(sKey));
                $scope.page.g_form.setValue(sKey, details[sKey]); //This will set the multirow once the key is matched.
            }

 

Thanks & Regards

Swathi Padighar

1 ACCEPTED SOLUTION

Swathi P
Tera Guru

I am able to achieve it by converting all the variables into String as few the variables are in numeric values so.

View solution in original post

11 REPLIES 11

@swathip so if you want to set the variable inside MVRS you cant set it individually you need to update the JSON and then set the JSON.

if poLIne is your value and you need to update the variable in the  JSON , update the JSON and then set it  like below 

 parsed[i].your_field_name_to_be_udpated

make sure you replace the variable back end name which you want to set in the above line in the script 

 

 $scope.fieldChange = function(poLine) {
    
        var three_way = $scope.page.g_form.getValue("invoice_line_items_three_way");// variable set

     var parsed =JSON.parse(three_way);
      
        for (var i=0; i<parsed.length; i++) {
             
               parsed[i].your_field_name_to_be_udpated = poLine;
               }
  $scope.page.g_form.setValue('invoice_line_items_three_way', JSON.stringify(parsed)); 

    };

MARK THIS NASWER CORRECT IF THIS HELPS YOU

 

@swathip i have updated the above code can you try that and let me know if it works ?

I tried it its not working and poLine is an object i need to set  7 variables in variable set . I need to set those variables in variable set through poLine object.

I want to set variables in variable set. How can i achieve it. Please suggest

hello @swathip ,

then try this so if poLine is a JSON and you want to set the individual elements in that JSON to MVRS 

For better understanding send me the Poline object i might help you in accessing elements.

i am assuming your poLine is in this below format

poLine = {

"key1":"value1",

"key2":"value2",

"key3":"value3",

"key4":"value4",

"key5":"value5,

"key6":"value6",

"key7":"value7",

}

 $scope.fieldChange = function(poLine) {
    
        var three_way = $scope.page.g_form.getValue("invoice_line_items_three_way");// variable set

     var parsed =JSON.parse(three_way);
      
        for (var i=0; i<parsed.length; i++) {
             
               parsed[i].your_field1_name_to_be_udpated = poLine.your_key1_name;
            parsed[i].your_field2_name_to_be_udpated = poLine.your_key2_name;
            parsed[i].your_field3_name_to_be_udpated = poLine.your_key3_name;
            parsed[i].your_field4_name_to_be_udpated = poLine.your_key4_name;
            parsed[i].your_field5_name_to_be_udpated = poLine.your_key5_name;
            parsed[i].your_field6_name_to_be_udpated = poLine.your_key6_name;
            parsed[i].your_field7_name_to_be_udpated = poLine.your_key7_name;
               }
  $scope.page.g_form.setValue('invoice_line_items_three_way', JSON.stringify(parsed)); 

    };