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');
 
}
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

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
 
 
 
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

9 REPLIES 9

Ahmmed Ali
Mega Sage

You can first read value of the variable C before setting new value and then set both old and new value in the variable by concatenating both the values.

 

Ex:

Assume you have new value in variable newVal

var existingValue = g_form.getValue("VARIABLE_C");

g_form.setValue("VARIABLE_C", existingValue  + "\n\n" + newVal);

 

 

Can you post the script which you have written? it will be easier to suggest changes there.

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ahmmed,

 

Thanks for your reply.

 

Please find the script which i have written,

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var t = g_form.getDisplayValue('description');
    var qa = g_form.getDisplayValue('quantity');
var ch;
ch = t + " : " + qa;
alert(ch);
 
g_form.setValue("store",ch);
       //g_form.setDisplayValue("store",ch);
    g_form.clearValue('test');
    g_form.clearValue('quantity');
 
}
 
 
Regards,
Suvedha.

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
 
 
 
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ali,

 

This got fixed. Thank you for your reply

But one thing, while populating the first line is taking line break.

 

can we do any thing for that?

 

Suvedha_0-1687259778370.png