To add on set value in catalog client script

Suvedha
Tera Expert

Hi all,

 

I have a requirement, a description field and quantity field, if on change of quantity , append both field description and quantity  and set the value in another field 'C', then clear the value of description field and quantity field, if again on change of quantity , append both field description and quantity and add the value in Variable 'C'.

 

In my case, while i am setting the value in Variable 'C', each time field is clearing and setting new Value

 

Is there a way to add the values in the field??

 

Thanks in advance.

Regards,

Suvedha

2 ACCEPTED SOLUTIONS

Hi @Suvedha ,

 

modify this script is c field value is nill then add directly else append with existing . something like below code:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var description = g_form.getDisplayValue('description');
    var qunatity= g_form.getDisplayValue('quantity');
var c_fieldValue = '';
if( g_form.getDisplayValue('c_field_name') == ''){
c_fieldValue  =  description + qunatity;
}
else{
c_fieldValue  = g_form.getDisplayValue('c_field_name') +  "\n\n" + description + qunatity;
}
alert(c_fieldValue  );
 
g_form.setValue("v",c_fieldValue  );
    g_form.clearValue('description');
    g_form.clearValue('quantity');
 
}

View solution in original post

Hello @Suvedha 

 

Please find updated script below:

 

var t = g_form.getDisplayValue('description');
var qa = g_form.getDisplayValue('quantity');
var ch;
ch = t + " : " + qa;
alert(ch);
 
var existingValue = g_form.getValue("store");
if(existingValue){
g_form.setValue("store", existingValue + "\n" + ch);
}else{
g_form.setValue("store",ch);
}
g_form.clearValue('test');
g_form.clearValue('quantity');
 
Thank you,
Ali
 
 
 

View solution in original post

9 REPLIES 9

Not applicable

Hi there,

 

You can create onChange client script on 'Quantity' field with the script as below:

var description = g_form.getValue('description');
var currentFieldC = g_form.getValue('field_C');
g_form.setValue('field_C', currentFieldC + ' ' + description + ' ' + newValue);
g_form.clearValue('description');
g_form.clearValue('quantity'');

 

Riya Verma
Kilo Sage

Hi @Suvedha ,

 

Hope you are doing great.

Try using below modified script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var description = g_form.getDisplayValue('description');
    var qunatity= g_form.getDisplayValue('quantity');
var c_fieldValue = '';
c_fieldValue  = g_form.getDisplayValue('c_field_name') +  "\n\n" + description + qunatity;
alert(c_fieldValue  );
 
g_form.setValue("v",c_fieldValue  );
    g_form.clearValue('description');
    g_form.clearValue('quantity');
 
}

 

 

In this, I have concatenated the value of c field existing value and appended with description and quantity and then set in c field and then later you can clear the value of description and quantity.

 

 

Hi Riya,

 

Thanks for your reply.

I am getting the white space in first line.

 can we remove this using trim()

Suvedha_0-1687262973247.png

Regards,

Suvedha

Hi @Suvedha ,

 

modify this script is c field value is nill then add directly else append with existing . something like below code:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var description = g_form.getDisplayValue('description');
    var qunatity= g_form.getDisplayValue('quantity');
var c_fieldValue = '';
if( g_form.getDisplayValue('c_field_name') == ''){
c_fieldValue  =  description + qunatity;
}
else{
c_fieldValue  = g_form.getDisplayValue('c_field_name') +  "\n\n" + description + qunatity;
}
alert(c_fieldValue  );
 
g_form.setValue("v",c_fieldValue  );
    g_form.clearValue('description');
    g_form.clearValue('quantity');
 
}

Hi Riya,

 

It worked. 

Thanks for your response.

 

Regards,

Suvedha.