Scenario: Check the previous value of state field and if not matches set the field value to current. Can any one explain me this scenario And how to debug it?

IAmIshan
Tera Guru

How to debug the question and solve it?

8 REPLIES 8

Harika Bhupathi
Giga Guru

Hello @Ishan 

Previous and Current are Business rules script objects

Previous value: before database record got updated with a new values, the old value it has referred as previous value

Current value: After database record got updated, the new updated value referred as current value

 

To test your scenario, you can create a after update business rule for incident table, where give condition as state changes --

in script check the previous value of state by giving previous.state in gs.info(previous.state);, same way for update also gs.info(current.state);

 

your logic would be like this

Note:give correct state choice values and fieldname which you want to update as per your requirement

var state = previous.state;

gs.info(state+"Previous value before update");

if(state != '1'){

current.state = '2';

current.otherFieldName = '';

gs.info(current.state + current.otherFieldName "current values after update");

current.update();

 

Please do mark the response as correct or helpful, if applicable

 

BR,

Harika

And what if we have to perform the above scenario using only client scripts and not business rules?

 

Regards,

Soumya

You can achieve this with onChange client script running on state field.

You get two predefined variables there oldValue and newValue.

You can compare there two variables and perform operation.

 

oldValue: It is the value which was set to field when form was loaded. (This is constant until you submit the form)

newValue: newValue of the field set by user, it will change as user changes field value.

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hello Anil,

I agree with your answer. Can you help me with the following script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {

return;
}

g_form.addInfoMessage('oldValue: ' + oldValue);

if (oldValue != newValue) {
g_form.setValue('state',newValue);
}
else {
alert('Prvoide new State..');
}

g_form.addInfoMessage('newValue: ' + newValue);

}

 

Using above code I am getting the error as shown in the image.

find_real_file.png

 

Regards,

Soumya