Retain Old value of a field using Onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 11:32 AM
Hi,
There are 2 fields on the form :
test : choice field (yes/no)
test1 : reference field
Case 1 : If no is selected from test, test1 should clear the value if it has any.
Case 2 : If yes is selected in test, then test1 should be mandatory.
Case 3 : In test, if first 'yes' is selected, then no and then again changed to yes, then it should return the old value that it contained in test1.
I want to implement this by using an Onchange client script.
Can someone please assist.
Thanks in Advance
Thanks,
Sunil Raikwar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 12:39 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 12:41 PM
Hi,
As I mentioned in my previous reply you have to use scratchpad to retain the old value.
Sent from Outlook Mobile<https://aka.ms/blhgte>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 04:00 AM
Hi Pradeep
My requirement is somewhat similar.
I am having state and substate field on my form . Substate depends on state.My requirement is when state is pending then substate is mandatory which is done by ui policy. Further only the assignee must be able to change the state to IN Progress . I have written an Onchange client script for this.
Problem is that when someone other than assignee changes the state from pending to In Progress then the state gets set to oldValue i.e. Pending but the substate value is not retained . It becomes ' --None--';
So how to solve this issue .
My CLient Script is as follows:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (oldValue=='-5'){
if(newValue=='8'){
var assigned = g_form.getValue('assigned_to');
if(assigned != g_user.userID) {
g_form.setValue('state',oldValue);
g_form.setValue('u_substate',g_scratchpad.substate);
}
}
g_form.setMandatory('work_notes',true);
}
Business Rule is :
function onDisplay(current, g_scratchpad) {
//This function will be automatically called when this rule is processed.
g_scratchpad.substate=current.u_substate;
}
Thanks
Snehal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 03:51 AM
Hi
Did you get any solution ? whether the scratchpad concept working?
Thanks
Snehal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2016 12:21 PM
Hi Sunil,
Suggestion given by Pradeep is the best practice, I will advice you to follow that script.
Just in case,
Please find the corrected script -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var oldTest1 = '';
//Type appropriate comment here, and begin script below
if(newValue == 'no'){
var oldTest1 = g_form.getValue('test1');
g_form.setValue('test1','');
}
else if(newValue == 'yes'){
if(oldTest1 != '')
g_form.setValue('test1',oldTest1);
g_form.setMandatory('test1');
}
}
Mark if it is helpful or correct, feedback is appreciated