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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2021 09:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2021 10:12 AM
Hello
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 11:44 AM
And what if we have to perform the above scenario using only client scripts and not business rules?
Regards,
Soumya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 11:51 AM
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
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2021 12:21 PM
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.
Regards,
Soumya